How to get the server IP Address?

后端 未结 4 1643
粉色の甜心
粉色の甜心 2020-12-29 03:32

Is there a 1 line method to get the IP Address of the server?

Thanks

4条回答
  •  [愿得一人]
    2020-12-29 04:06

    From searching the net I found following code: (I couldn't find a single line method there)

    string myHost = System.Net.Dns.GetHostName();
    
    // Show the hostname 
    
    MessageBox.Show(myHost);
    
    // Get the IP from the host name
    
    string myIP = System.Net.Dns.GetHostEntry(myHost).AddressList[index].ToString();
    
    // Show the IP 
    
    MessageBox.Show(myIP);
    

    -> where index is the index of your ip address host (ie. network connection).

    Code from: http://www.geekpedia.com/tutorial149_Get-the-IP-address-in-a-Windows-application.html

提交回复
热议问题