1

I've searched a lot Javascript, C#, ASP.NET scripts, for a script that gets public IP and hostname but none of them could get me IP and hostname, only the ones that used third part sites to aprse the info from.

How can I do that without having to parse from third part websites? All scripts that I've tested returned my IP as hostname, or even Windows domain name.

André Ikvmo
  • 89
  • 3
  • 10
  • 2
    Everything on that page is just displaying something the browser sends in the [HTTP headers](https://en.wikipedia.org/wiki/HTTP_headers). – Two-Bit Alchemist Mar 10 '14 at 23:27
  • possible duplicate of [How can I get the client's IP address in ASP.Net MVC?](http://stackoverflow.com/questions/2577496/how-can-i-get-the-clients-ip-address-in-asp-net-mvc) – Silvermind Mar 10 '14 at 23:46

1 Answers1

1

You just need to use the Dns class:

string hostname = Dns.GetHostEntry("some IP address").HostName;
itsme86
  • 19,266
  • 4
  • 41
  • 57
  • Hi, it really did work, thank you very much, I've spent hours looking for a solution, also, could you tell me a way to accurately get an external IP from clients? The ones I've tried got the internal IP. – André Ikvmo Mar 10 '14 at 23:37
  • @AndréIkvmo If the server you're connecting to is on the same network, you'll always see the internal IP. The only way you'll get around it is to route through an external host. – itsme86 Mar 10 '14 at 23:39
  • Yes I've tried it, the server is on another machine, same network, but still, I've accessed it by the browser, on the public url (www.site.com), and it returned like proxy and gateway IP's, some scripts returned local IP. – André Ikvmo Mar 10 '14 at 23:43
  • @AndréIkvmo Just make sure you use the IP address that the server sees instead of the one that the client is sending. – itsme86 Mar 10 '14 at 23:49