I need to find User’s local IP. The server is behind a router, so I cannot use any server-side method. I also don’t want to use any 3rd party service like http://jsonip.appspot.com/ because I tested it and its server goes down from time to time.
Using Java, I I want to get the IP through something like
<script type="text/javascript">
function myIP() {
var yip2 = java.net.InetAddress.getLocalHost();
var yip = yip2.getHostAddress();
return yip;
} //end myIP
alert("your machine's local network IP is " + myIP())
</script>
but It’s not working. How can I get it work?
Sounds like you are "stuck" with what you have already provided. Your script actually got me curious because on first glance it did seem you were mixing server and client (java and javascript) + all the comments pointed to it. But curiosity is good thing 🙂
Apparently, though not really reliable you can call Java methods in supporting browsers. Java is client side too (the concept that was lost).
I will copy and paste this, I’ve never tried (because I’ve never been limited the same way as you are):
Taken from About.com – which also describes what you need to do to at least give it a chance to work (upload, can’t do it from local).
UPDATE:
Forget it. I’m not a java guy (in the first place), as @Esailija has noted, the script above will not (no longer) work:
Reference here