Get local IP address

前端 未结 26 2858
野的像风
野的像风 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:44

    string str="";
    
    System.Net.Dns.GetHostName();
    
    IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(str);
    
    IPAddress[] addr = ipEntry.AddressList;
    
    string IP="Your Ip Address Is :->"+ addr[addr.Length - 1].ToString();
    

提交回复
热议问题