I am checking ripe ncc db for country codes of IP-Adresses in order to prevent registrations from certain countries.
/**
* Get country code from Ip.
* @input IP number
* @output Country Code.
*/
function parse_ip($ip){
$DATABASE = "whois.ripe.net";
$info = '' ;
$sk= @fsockopen($DATABASE, 43, $errno, $errstr, 1) or error_log('Unable to connect to whois server');
if(!empty($sk)){
@fputs ($sk, $ip ."\r\n") or error_log ('Unable to send data to whois server in act_functions.inc from parse_ip()');
while (!feof($sk)){
$info.= fgets ($sk, 2048);
}
preg_match( '/^\x20*country\x20*:\x20*(\w{2})/im',$info, $country_code);
return $country_code[1];
}
else return false;
}
There are some adresses which seem not to be managed by them, how is this possible?
inetnum: 135.197.0.0 - 136.142.255.255
netname: NON-RIPE-NCC-MANAGED-ADDRESS-BLOCK
descr: IPv4 address block not managed by the RIPE NCC
How could I implement an alternative if the block is not managed?