Get local IP address

前端 未结 26 2846
野的像风
野的像风 2020-11-22 10:07

In the internet there are several places that show you how to get an IP address. And a lot of them look like this example:

String strHostName = string.Empty;         


        
26条回答
  •  孤独总比滥情好
    2020-11-22 10:55

    Obsolete gone, this works to me

    public static IPAddress GetIPAddress()
    { 
     IPAddress ip = Dns.GetHostAddresses(Dns.GetHostName()).Where(address => 
     address.AddressFamily == AddressFamily.InterNetwork).First();
     return ip;
    }
    

提交回复
热议问题