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

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

问题描述

我这里有一些在 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 地址.这就是我要的.问题是它在我们的 IPv6 机器上返回字符串::1:",我认为这是 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 地址......并且从它自身执行 "ping -4 machinename" 会提供正确的 IPv4 地址......但定期对其进行 Pingfrom 本身给出 "::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?

推荐答案

你看过 返回所有地址,丢弃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?

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

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