Get Local PC IP


This code is use to get the local pc ip address. you can use this in window/web application too.

MessageBox.Show(GetLocalPCIP());

Function


protected string GetLocalPCIP()
{
string LocalIP = null;

System.Net.IPHostEntry IPHostEntry = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName());

foreach (System.Net.IPAddress IPAddress in IPHostEntry.AddressList)
{
if (IPAddress.AddressFamily.ToString() == "InterNetwork")
{
LocalIP = IPAddress.ToString();
}
}
return LocalIP;
}


All the Best
:)


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: