Created
January 28, 2014 15:41
-
-
Save pachecoder/8669937 to your computer and use it in GitHub Desktop.
Get the local ip address of the principal network adapter card.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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