To get the IP of the javascript user it is possible to use some website, I recommend using ipify's api .
link
Use the JQuery version code it's pretty easy that normal javascript, put this in your head first:
<script type="application/javascript" src="https://api.ipify.org?format=jsonp&callback=getIP"></script>
Putexactlythisinyourscriptelementtorunit,doalittletestfirst.requiresanupdatedoroldversionofJQuery.
$(function(){$.getJSON("https://api.ipify.org?format=jsonp&callback=?",
function(json) {
document.write("Meu IP público é: ", json.ip);
}
);
});
Feel free to test the script with what I put below. Remember, the api website is a little slow I think so ... it may take about 15 seconds for the IP to be updated, obviously it depends on your internet.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script><html><head><scripttype="application/javascript" src="https://api.ipify.org?format=jsonp&callback=getIP"></script><scripttype="application/javascript">
$(function() {
$.getJSON("https://api.ipify.org?format=jsonp&callback=?",
function(json) {
document.write("Meu IP público é: ", json.ip);
}
);
});
</script>
</head>
<body>
</body>
</html>