Skip to content

Instantly share code, notes, and snippets.

@vanodevium
Created September 29, 2023 08:47
Show Gist options
  • Save vanodevium/70b463b46745defb886a7e645f0d6e67 to your computer and use it in GitHub Desktop.
Save vanodevium/70b463b46745defb886a7e645f0d6e67 to your computer and use it in GitHub Desktop.
Fetch ip and country from Cloudflare
(async () => {
const fetchCloudFlare = async () => {
return fetch('https://www.cloudflare.com/cdn-cgi/trace')
.then(response => response.text())
.then(data => {
const $data = {};
(data || "").trim().split("\n").map((el) => {
if (el.includes('ip=')) {
$data.ip = el.replace('ip=', '');
}
if (el.includes('loc=')) {
$data.country = el.replace('loc=', '');
}
});
return $data;
});
}
console.log(await fetchCloudFlare())
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment