cloudflare-trace-api
cloudflare-trace-api copied to clipboard
Javascript Example to JSON
async function getCloudflareJSON(){
let data = await fetch('https://1.0.0.1/cdn-cgi/trace').then(res=>res.text())
let arr = data.trim().split('\n').map(e=>e.split('='))
return Object.fromEntries(arr)
}
getCloudflareJSON().then(console.log)
Output:
{fl: "202f225", h: "1.0.0.1", ip: "47.37.137.777", ts: "1625581799.09", visit_scheme: "https", …}
How would you take this and filter out everything but "ip" and save that ip value as a variable to use later?
async function somefunc(){
let cloudflareJSON = await getCloudflareJSON()
console.log(cloudflareJSON.ip)
}