Thursday, 12 March 2015

How to get local ip address of host in c#



public string LocalIPAddress()
 {
   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;
 }



To get ip address of local host

No comments:

Post a Comment