Reputation: 17288
I want to get the name of the computer or its IP address through javascript.
How can this be obtained?
Upvotes: 4
Views: 12241
Reputation: 9
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>
Upvotes: -1
Reputation: 1073968
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.
Upvotes: 4
Reputation: 90989
It's not possible. JavaScript doesn't have access outside browser's sandbox.
Upvotes: 0