从 IPHostEntry 获取有效 IP
我尝试使用此方法获取计算机的 IP 地址
var ipadd = Dns.GetHostEntry(Dns.GetHostName());
foreach (var ipAddress in ipadd.AddressList)
Console.WriteLine("IP Address: {0}", ipAddress);
我的计算机中只有一张连接到路由器的网卡。它是 ipv4,但这一行代码给了我 4 个 IPAddress,其中 3 个是 ipv6,一个是 ipv4,这是有效的。我想问为什么会这样?
谢谢
I tried to get the IPAddress of my computer using this
var ipadd = Dns.GetHostEntry(Dns.GetHostName());
foreach (var ipAddress in ipadd.AddressList)
Console.WriteLine("IP Address: {0}", ipAddress);
I have only one network card in my computer which is connected to the router. It is ipv4 but this line of code gives me 4 IPAddress 3 of them are ipv6 and one is ipv4 which is the valid one. I like to ask why is that so ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)