Get machine Public IP

2779 views c#
2

Trying to get the public address of the machine using c#. Unable to get Public IP. Is there any possible to get machine pubic IP address without using external API and libraries in c#

answered question

1 Answer

2

To get local IP Address.

public void GetLocalIPAddress()
{
  string hostName = Dns.GetHostName(); // Retrive the Name of HOST  

  // Get the IP  
  string myIP = Dns.GetHostByName(hostName).AddressList[0].ToString();  
  Console.WriteLine("My IP Address is :"+myIP);  
  Console.ReadKey();  
}

posted this

Have an answer?

JD

Please login first before posting an answer.