Feature #3727
Print country code of the user
Start date:
09/20/2024
Due date:
% Done:
100%
Estimated time:
0.25 h
Description
If you find div id="rapidken-country-code" on a page, print the country code from which the user is accessing the page. running "https://www.cloudflare.com/cdn-cgi/trace" provides output as follows. Code such as the script below can be used to print the country code by accessing the value of the 'loc' field.
fl=374f108
h=www.cloudflare.com
ip=2401:4900:1cc4:2c82:20d0:8a8c:cf55:fe5d
ts=1726815351.852
visit_scheme=https
uag=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36
colo=BLR
sliver=none
http=http/2
loc=IN
tls=TLSv1.3
sni=plaintext
warp=off
gateway=off
rbi=off
kex=X25519Kyber768Draft00
<script type="text/javascript">
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState 4 && this.status 200) {
var country_code = this.responseText.replace(/(\r\n|\n|\r)/gm,"").split('loc=');
country_code = country_code[1].split('tls=');
country_code = country_code[0];
document.getElementById("countrycode-container").innerHTML = country_code;
}
};
//OPEN HTTP Request
xhttp.open("GET", "https://www.cloudflare.com/cdn-cgi/trace", true);
xhttp.send();
</script>