Answers for "javascript get the ip address"

2

how to get ip address in javascript

fetch('https://api.ipify.org/?format=json')
  .then(response => response.json())
// Returns 
{
 "ip": "user_ip"
}
Posted by: Guest on April-24-2021
5

how to get user ip address in javascript

// You can't extract the the public ip from with in the browser
// but you CAN use a third party, there are a lot of them out there
// I use www.ipify.org/

// because, according to them:
//
// 1. You can use it without limit (even if you're doing millions of 
//    requests per minute). 
// 2. ipify is completely open source (check out the GitHub repository).

//Here's a WORKING JS EXAMPLE:

<script>
function getIP(json) {
  alert("My public IP address is: " + json.ip);
}
</script>
<script src="https://api.ipify.org?format=jsonp&callback=getIP"></script>

// as seperate script tag
<script type="application/javascript" src="https://api.ipify.org?format=jsonp&callback=getIP"> </script>
Posted by: Guest on June-18-2020

Code answers related to "javascript get the ip address"

Code answers related to "Javascript"

Browse Popular Code Answers by Language