How to get computer name or IP from javascript?

Hemanshu Bhojak picture Hemanshu Bhojak · May 13, 2010 · Viewed 11.1k times · Source

I want to get the name of the computer or its IP address through javascript.

How can this be obtained?

Answer

T.J. Crowder picture T.J. Crowder · May 13, 2010

As Imran and Jamie have said, you can't do it entirely on the client.

It's trivial to get the computer's apparent, public IP address — but only if you send a request to your server, either by using XmlHTTPRequest or by appending a script tag to the head section or similar. The server can respond to that request by echoing the IP from which the request apparently came. How you get that information depends on your server-side technology.

That'll get you the IP (using a server request), but I don't know of a way to get the computer name.