I've changed my approach since freegeoip.net will be closed.
I've started to experiment with DNSBL's which is a simpler and in my case faster approach.
Im playing with the following code.
----
% <?php function dnsblTjek( $ip_address = NULL, $dnsbl = NULL ) { if( filter_var($ip_address, FILTER_VALIDATE_IP) === false ) //Invalid IP return false; /*reverse IP address */ $array = explode( ".", $ip_address ); $array = array_reverse( $array ); $reverse_ip = implode( ".", $array ); /* Perform the check */ $result = gethostbyname( $reverse_ip.".".$dnsbl ); return $result; } function isDanish($ipadress){ $returncode= dnsblTjek( $ipadress, "zz.countries.nerd.dk" ); if ($returncode == '127.0.0.208') //Code for denmark - https://en.wikipedia.org/wiki/ISO_3166-1_numeric return true; else return false; } function isTorNode ($ipadress){ $returncode= dnsblTjek( $ipadress, "torexit.dan.me.uk" ); if ($returncode == '127.0.0.100') //see dan.me.uk return true; else return false; } isTorNode("185.220.101.6"); isDanish("185.220.101.6"); %