由网友(国际美男)分享简介:我有以下的code:Dim ipAdd As IPAddress = Dns.GetHostEntry(strHostname).AddressList(0)Dim strIP As String = ipAdd.ToString()当我转换为字符串,而不是IPv4地址192.168.1.0一样或类似的,我得到IP...
我有以下的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);
相关推荐
最新文章