Search code examples
javascriptcomputer-nameip-address

How to get computer name or IP from javascript?


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

How can this be obtained?


Solution

  • 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.