Friday, February 3, 2012

To Get Local Machine IP in C#

What is the syntax for getting the computer's own (if possible, external) IP address?
IPHostEntry host; string localIP = "?";
host
= Dns.GetHostEntry(Dns.GetHostName()); foreach (IPAddress ip in host.AddressList) {
   
if (ip.AddressFamily.ToString() == "InterNetwork")
   
{
        localIP
= ip.ToString();
   
} } return localIP;  

No comments:

Post a Comment