Is there any way to retrieve a client IP using javascript only? Or every jquery only? I don't think so, but I want to make sure.
-
AFAIK there's no way to get this sort of information from a browser, but even if there was, what use would it be? Most browsers run behind a NAT firewall and you still wouldn't know the public address. – May 10 '15 at 01:02
-
possible duplicate of [Get client IP using just JavaScript?](http://stackoverflow.com/questions/391979/get-client-ip-using-just-javascript) – ThisClark May 10 '15 at 01:22
2 Answers
You must use a server-side service. There are some publicly available you can consume, such as:
<html>
<head>
<title>What is my IP</title>
</head>
<body>
<script>
VIH_DisplayOnPage = "no";
</script>
<script src="http://scripts.hashemian.com/js/visitorIPHOST.js.php"></script>
<script>
document.write('Your IP is ' + VIH_HostIP);
</script>
</body>
</html>

- 14,352
- 10
- 69
- 100
No, there is no way to get a client IP using JavaScript only.
Consider the counter argument that it is possible: Supposed you have a static HTML page sitting on your desktop, with no internet connection and no linked resources. What would the IP be reported as? Would it have any significance?
Back in the days of ActiveX
, you could have played with things like this:
obj = new ActiveXObject("rcbdyctl.Setting");
rslt = obj.GetIPAddress;
But those days are long gone. Besides, if a client it behind a NAT, then only a LAN IP would be reported. You'd need to probe a server somewhere to get the WAN IP reported back.
You should use server-side code to do this. You can use a service like ip.jsontest.com
, as one example. It returns a JSON object like this:
{"ip": "152.178.193.25"}
Query this using client-side AJAX.

- 23,254
- 3
- 51
- 94