Reputation: 23
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
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