I need to somehow pull the clients IP address using pure javascript, no server side code, not even SSI.
Any ideas?
I'm not against using a free 3rd party script, if someone can suggest one. This is an emergency stop gap until we can deploy new code.
I need to somehow pull the clients IP address using pure javascript, no server side code, not even SSI.
Any ideas?
I'm not against using a free 3rd party script, if someone can suggest one. This is an emergency stop gap until we can deploy new code.
You can't. And even if you could, it would be the address of the machine, which is useless if they're communicating via a proxy or NAT. Find a way to get it server-side.
Not possible in general unless you use some kind of external service.
Even if you have java available to your JS, the following returns 127.0.0.1 for me, so I'd venture to say "No" as well:
alert(java.net.InetAddress.getLocalHost().getHostAddress());
There isn't really a way.
This goes through some of the possibilities. The code that uses Java will break if the user has multiple interfaces.
http://nanoagent.blogspot.com/2006/09/how-to-find-evaluate-remoteaddrclients.html
I'm no javascript guru, but if its possible you could open an iframe with http://www.whatismyip.com/automation/n09230945.asp as the source and read the content of the frame.
Edit: this wont work because of the cross domain security.
Well, I am digressing from the question, but I had a similar need today and though I couldn't find the ID from the client using Javascript, I did the following.
On the server side: -
<div style="display:none;visibility:hidden" id="uip"><%= Request.UserHostAddress %></div>
Using Javascript
var ip = $get("uip").innerHTML;
I am using ASP.Net Ajax, but you can use getElementById instead of $get().
What's happening is, I've got a hidden div element on the page with the user's IP rendered from the server. Than in Javascript I just load that value.
This might be helpful to some people with a similar requirement like yours (like me while I hadn't figure this out).
Cheers!
You can, relaying it via server side with JSONP
And while googling to find one, found it here on SO http://stackoverflow.com/questions/102605/can-i-lookup-the-ip-address-of-a-hostname-from-javascript
<script type="application/javascript">
    function getip(json){
      alert(json.ip); // alerts the ip address
    }
</script>
<script type="application/javascript" src="http://jsonip.appspot.com/?callback=getip"></script>
The last one is jsonpadding tecnique, and is the only possible actually.