本文介绍了净ip地址的IPv4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下的code:
Dim ipAdd As IPAddress = Dns.GetHostEntry(strHostname).AddressList(0)
Dim strIP As String = ipAdd.ToString()
当我转换为字符串,而不是IPv4地址192.168.1.0一样或类似的,我得到IPv6版本:FD80 :: 5dbe:5d89:E51B:D313地址
When I convert to String instead of an IPv4 address like 192.168.1.0 or similar I get the IPv6 version: fd80::5dbe:5d89:e51b:d313 address.
有没有一种方法可以让我返回从ip地址类型IPv4地址?
Is there a way I can return the IPv4 address from IPAddress type?
感谢
推荐答案
而不是无条件地采取AddressList中的第一个元素,你可以采取的第一个IPv4地址:
Instead of unconditionally taking the first element of the AddressList, you could take the first IPv4 address:
var address = Dns.GetHostEntry(strHostname)
.AddressList
.First(ip => ip.AddressFamily == AddressFamily.InterNetwork);
这篇关于净ip地址的IPv4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!