Created
November 10, 2021 04:51
-
-
Save Anenth/0a2aaf402f894a23ef486435d2bf5a22 to your computer and use it in GitHub Desktop.
Get IP and Location from the browser js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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