2014-12-02 23 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()); 
    }     
}