Created
October 20, 2012 21:29
-
-
Save user454322/3924878 to your computer and use it in GitHub Desktop.
getting IP info with JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script type="text/javascript"> | |
function getLocalIP(){ | |
var yip2=java.net.InetAddress.getLocalHost(); | |
var yip=yip2.getHostAddress(); | |
document.getElementById("ip_addr").innerHTML=yip; | |
} | |
var ipx ="ERROR" | |
function getPublicIPJSON(data){ | |
ipx = data.host | |
} | |
function setPublicIPJSON(){ | |
document.getElementById("ip_addr").innerHTML=ipx; | |
} | |
</script> | |
<script type="text/javascript" src="http://smart-ip.net/geoip-json?callback=getPublicIPJSON"> | |
</script> | |
</head> | |
<body> | |
<h1>IP TEST</h1> | |
<p id="ip_addr">IP</p> | |
<button type="button" onclick="getLocalIP()">Display IP using Java</button> | |
<button type="button" onclick="setPublicIPJSON()">Display IP info using internet service</button> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment