Get IP Address

| |
Public Function GetIPAddress() As String
        Dim h As System.Net.IPHostEntry = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName)
        Return h.AddressList.GetValue(0).ToString
    End Function
public string GetIPAddress()
	{
		string myHost = System.Net.Dns.GetHostName();
		string myIP = null;

		for (int i = 0; i <= System.Net.Dns.GetHostEntry(myHost).AddressList.Length - 1; i++)
		{
			if (System.Net.Dns.GetHostEntry(myHost).AddressList[i].IsIPv6LinkLocal == false)
			{
				myIP = System.Net.Dns.GetHostEntry(myHost).AddressList[i].ToString();
			}
		}
		return myIP;
	}
Originally Posted on December 14, 2013
Last Updated on November 13, 2015
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.