Skip to content

Instantly share code, notes, and snippets.

@metavige
Created November 19, 2013 09:20
Show Gist options
  • Save metavige/7542576 to your computer and use it in GitHub Desktop.
Save metavige/7542576 to your computer and use it in GitHub Desktop.
getlocalip
public static string localIPAddress()
{
IPHostEntry host;
string localIP = "";
host = Dns.GetHostEntry(Dns.GetHostName());
foreach (IPAddress ip in host.AddressList)
{
localIP = ip.ToString();
String[] temp = localIP.Split('.');
if (ip.AddressFamily == AddressFamily.InterNetwork && temp[0] == "192")
{
break;
}
else localIP = null;
}
return localIP;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment