Skip to content

Instantly share code, notes, and snippets.

@pachecoder
Created January 28, 2014 15:41
Show Gist options
  • Save pachecoder/8669937 to your computer and use it in GitHub Desktop.
Save pachecoder/8669937 to your computer and use it in GitHub Desktop.
Get the local ip address of the principal network adapter card.
public string getLocalIPAddress()
{
IPHostEntry host;
string localIP = "";
host = Dns.GetHostEntry(Dns.GetHostName());
foreach (IPAddress ip in host.AddressList)
{
if (ip.AddressFamily == AddressFamily.InterNetwork)
{
localIP = ip.ToString();
break;
}
}
return localIP;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment