Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Javascript Example to JSON #3

Open
fawazahmed0 opened this issue Jul 6, 2021 · 2 comments
Open

Javascript Example to JSON #3

fawazahmed0 opened this issue Jul 6, 2021 · 2 comments

Comments

@fawazahmed0
Copy link
Owner

fawazahmed0 commented Jul 6, 2021

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", …}
@Wamy-Dev
Copy link

How would you take this and filter out everything but "ip" and save that ip value as a variable to use later?

@fawazahmed0
Copy link
Owner Author

async function somefunc(){
let cloudflareJSON = await getCloudflareJSON()
console.log(cloudflareJSON.ip)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants