0

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

https://apps.db.ripe.net/db-web-ui/#/query?bflag=true&dflag=false&rflag=false&searchtext=136.0.0.150&source=RIPE#resultsSection

How could I implement an alternative if the block is not managed?

merlin
  • 2,717
  • 3
  • 29
  • 59

1 Answers1

0

The RIPE database does not provide details for IP addresses managed by another Regional Internet Registry (RIR), in this case ARIN. You could try to use whois.iana.org as WHOIS source to figure out the corresponding RIR (and perform a second WHOIS lookup, this time to the RIR). But keep in mind that the country attribute that you're currently parsing is not reliable at RIPE, because „it has never been specified what this country represents. It could be the location of the head office of a multi-national company or where the server centre is based or the home of the End User. Therefore, it cannot be used in any reliable way to map IP addresses to countries“. On the other hand, if you're looking for IP geo-location, it might be helpful to use an existing and maintained geo-location database rather reinventing the wheel, because the WHOIS services have also lookup limits.

rsc
  • 389
  • 2
  • 10