获得从Dns.GetHostEntry IPv4地址()地址、Dns、GetHostEntry

2023-09-02 10:26:09 作者:七分情

我有一些在这里code上的IPv4机器的伟大工程,但我们构建服务器(在IPv6)的失败。简而言之:

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);

该文档GetHostEntry说,传递的String.Empty将让你的本地主机的IPv4地址。这就是我想要的。问题是,它的返回字符串:: 1:我们的IPv6的机器,我相信这是IPv6的地址

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.

这是任何其他的IPv4机执行ping本机提供了一个很好的IPv4地址...和做一个平-4计算机名从本身提供了正确的IPv4地址....但定期查验其从本身赋予:: 1:

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:".

我怎样才能获得IPv4的这台机器,从本身?

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

推荐答案

你看all地址的在返回,丢弃的family InterNetworkV6 ,只保留IPv4的那些?

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

 
精彩推荐