1

My problem is that I have 127.0.0.1 but this is the private IP address of localhost.

How can I get public IP address of my localhost using C# asp.net?

Luís Cruz
  • 14,780
  • 16
  • 68
  • 100
Tarang Gosai
  • 23
  • 1
  • 3

1 Answers1

1

try this code

IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName());
IPAddress ip= host.AddressList.Where(ip => ip.AddressFamily == AddressFamily.InterNetwork).FirstOrDefault();

update you are looking for your public IP

to get it you should use http get to services like http://checkip.dyndns.org

check this answer that already exist in SO

Community
  • 1
  • 1
faby
  • 7,394
  • 3
  • 27
  • 44