从Dns.GetHostEntry()获取IPv4地址 [英] Get IPv4 addresses from Dns.GetHostEntry()

查看:133
本文介绍了从Dns.GetHostEntry()获取IPv4地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里有一些代码,在IPv4机器上工作得很好,但在我们的构建服务器(IPv6)上,它失败了。简单来说:

  IPHostEntry ipHostEntry = Dns.GetHostEntry(string.Empty); 

GetHostEntry的文档说,传入string.Empty将会获得本地主机的IPv4地址。这就是我想要的问题是它在IPv6机器上返回字符串:: 1:,我相信是IPv6地址。



从任何其他IPv4机器中ping机器给出一个很好的IPv4地址...并且从本身做一个ping -4 machinename给出了正确的IPv4地址....但是它自身定期ping它给出了:: 1:。 / p>

如何从本机获取此机器的IPv4?

解决方案

你看过返回中的所有地址,丢弃 Family InterNetworkV6 ,并且只保留IPv4?


I've got some code here that works great on IPv4 machines, but on our build server (an IPv6) it fails. In a nutshell:

IPHostEntry ipHostEntry = Dns.GetHostEntry(string.Empty);

The documentation for GetHostEntry says that passing in string.Empty will get you the IPv4 address of the localhost. This is what I want. The problem is that it's returning the string "::1:" on our IPv6 machine, which I believe is the IPv6 address.

Pinging the machine from any other IPv4 machine gives a good IPv4 address... and doing a "ping -4 machinename" from itself gives the correct IPv4 address.... but pinging it regularly from itself gives "::1:".

How can I get the IPv4 for this machine, from itself?

解决方案

Have you looked at all the addresses in the return, discard the ones of family InterNetworkV6 and retain only the IPv4 ones?

这篇关于从Dns.GetHostEntry()获取IPv4地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆