2014-12-02 24 views
4

检索50我有一台linux(ubuntu服务器14.04)250 ips机器。当我用单声道运行我的C#代码时,它只能检索到50 ips。C# - 机器有250 ips,我只能从代码

所有ips配置正确,我在java中有相同的代码,并且找到所有250 ips,并且可以绑定到。

我曾尝试:

Dns.GetHostByName(Dns.GetHostName()).AddressList; 

Dns.GetHostAddresses(string.Empty); 

都返回50 ips的?

所以,我的问题是,是否有限制在C#上可以发现多少IPS?或任何其他原因,任何人都知道为什么会发生这种情况?

+0

您是否与本地Windows和.NET尝试,在Linux上,而不是单? – RenniePet 2014-12-02 12:54:11

+0

不幸的是我不能,因为它是一个Ubuntu服务器机器.. – felbus 2014-12-02 13:23:04

+0

然后,我认为你应该添加单声道作为你的问题的标签,因为它是未知的,如果这是一个.NET问题。 – RenniePet 2014-12-02 13:47:23

回答

4

我会建议切换到不同的方法来获取相同的数据。

System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces() 

http://msdn.microsoft.com/en-us/library/system.net.networkinformation.networkinterface.getallnetworkinterfaces%28v=vs.110%29.aspx

你所要求的代码做的是把当前的机器,并询问什么都注册IP地址的第二个服务器。相反,向服务器询问您的IP地址是什么会更容易也更可靠。有些可能不会注册到DNS服务器,无论是本地还是远程。

0

Josh的答案是正确的,但为了完整性,下面是完整的代码来获取IP地址:

var interfaces = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces(); 

foreach (var netInterface in interfaces) 
{ 
    IPInterfaceProperties ipProps = netInterface.GetIPProperties(); 

    foreach (UnicastIPAddressInformation addr in ipProps.UnicastAddresses) 
    { 
      Console.WriteLine(addr.Address.ToString()); 
    }     
}