Skip to content

Instantly share code, notes, and snippets.

@stenito
Last active February 15, 2021 12:32
Show Gist options
  • Save stenito/c15859c6a9bedcf8ea5e750e7831c414 to your computer and use it in GitHub Desktop.
Save stenito/c15859c6a9bedcf8ea5e750e7831c414 to your computer and use it in GitHub Desktop.
Get public IP address (or wan IP address) using fetch JavaScript function (not supported in IE)
function getPublicIP() {
fetch('http://httpbin.org/ip')
.then(response => response.json())
.then(data => {
// do what you want to do with the IP address
// ... eg. log it to the console
console.log(data.origin);
});
}
getPublicIP()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment