Last active
February 15, 2021 12:32
-
-
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)
This file contains hidden or 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 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