Tarang Gosai
Tarang Gosai

Reputation: 23

How to get the public IP address of localhost using asp.net c#?

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?

Upvotes: 1

Views: 5280

Answers (1)

faby
faby

Reputation: 7558

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

Upvotes: 1

Related Questions