Skip to content

Instantly share code, notes, and snippets.

@Anenth
Created November 10, 2021 04:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Anenth/0a2aaf402f894a23ef486435d2bf5a22 to your computer and use it in GitHub Desktop.
Save Anenth/0a2aaf402f894a23ef486435d2bf5a22 to your computer and use it in GitHub Desktop.
Get IP and Location from the browser js
function getCloudflareJSON(data): Promise<{
fl: string
h: string
ip: string
ts: number
visit_scheme: string
uag: string
colo: string
http: string
loc: string
tls: string
sni: string
warp: string
gateway: string
}> {
return fetch("https://1.1.1.1/cdn-cgi/trace")
.then(res => res.text())
.then(data => {
const arr = data
.trim()
.split("\n")
.map(e => e.split("="))
return Object.fromEntries(arr)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment