Created
May 13, 2015 12:10
-
-
Save CodyKochmann/fb8033e14d73c2f35e14 to your computer and use it in GitHub Desktop.
returns the users ip address in 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
function myIP() { | |
// returns the users ip address | |
// ref link: http://stackoverflow.com/questions/391979/get-client-ip-using-just-javascript | |
if (window.XMLHttpRequest) xmlhttp = new XMLHttpRequest(); | |
else xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); | |
xmlhttp.open("GET","http://api.hostip.info/get_html.php",false); | |
xmlhttp.send(); | |
hostipInfo = xmlhttp.responseText.split("\n"); | |
for (i=0; hostipInfo.length >= i; i++) { | |
ipAddress = hostipInfo[i].split(":"); | |
if ( ipAddress[0] == "IP" ) return ipAddress[1]; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Will it return the private IP address?