Get machine Public IP

2779 views c#

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


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);  

posted this

Have an answer?


Please login first before posting an answer.