Trace current user's location via javascript with CloudFlare provided the /cdn-cgi/trace is enabled.
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($){ | |
$(function(){ | |
$.ajax({ | |
contentType: 'application/text; charset=utf-8', | |
crossBrowser: true, | |
type: 'GET', | |
url: '/cdn-cgi/trace', | |
}).done(function(d){ | |
var data = d.replace(/[\r\n]+/g, '","').replace(/\=+/g, '":"'); | |
data = '{"' + data.slice(0, data.lastIndexOf('","')) + '"}'; | |
var jsondata = $.parseJSON(data); | |
console.log(jsondata.loc); | |
}); | |
}); | |
})(jQuery); |
fetch(`https://${location.hostname}/cdn-cgi/trace`)
.then(res => res.text() ).then(t => {
var data = t.replace(/[\r\n]+/g, '","').replace(/\=+/g, '":"');
data = '{"' + data.slice(0, data.lastIndexOf('","')) + '"}';
var jsondata = JSON.parse(data);
console.log(jsondata);
})
code if page is add to cloudflare
- /cdn-cgi/trace is work on every domain on cloudflare DNS or network
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
use https://cf-ns.com/cdn-cgi/trace in China