'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 1:[1]

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.

Solution 2:[2]

It's not possible. JavaScript doesn't have access outside browser's sandbox.

Solution 3:[3]

Javascript can't do it alone, you have to use JQuery for that below is the code snippet

<script>
$.getJSON("https://api.ipify.org?format=json", function (data) {
  console.log("Ip address ====>", data.ip);
})
</script>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 T.J. Crowder
Solution 2 Imran
Solution 3 Rahul Vijaykar