Skip to content

Instantly share code, notes, and snippets.

@miguelmota
Created July 29, 2021 05:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miguelmota/ecf4e58d97902d2cb09488d02ecd9aba to your computer and use it in GitHub Desktop.
Save miguelmota/ecf4e58d97902d2cb09488d02ecd9aba to your computer and use it in GitHub Desktop.
JavaScript get IP address using Cloudflare
<html>
<head>
<title>IP</title>
</head>
<body>
<output id="output"></output>
<script>
const output = document.getElementById('output')
fetch('https://www.cloudflare.com/cdn-cgi/trace')
.then(res => res.text())
.then(text => {
output.innerHTML += text.split('\n').join('<br>')
})
.catch(err => {
output.innerHTML = err.message
})
</script>
<body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment