Created
November 19, 2013 09:20
-
-
Save metavige/7542576 to your computer and use it in GitHub Desktop.
getlocalip
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 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