Author image Nigel Wetters Gourlay


IP::Country::DNSBL - IP geolocation via DNS


  use IP::Country::DNSBL;
  my $reg = IP::Country::DNSBL->new();
  print $reg->inet_atocc('')   ."\n";
  print $reg->inet_atocc('') ."\n";


Finding the home country of a client using only the IP address can be difficult. Looking up the domain name associated with that address can provide some help, but many IP address are not reverse mapped to any useful domain, and the most common domain (.com) offers no help when looking for country.

This module queries a DNSBL server to find the correct country code.


The constructor zero or one arguments.

  use IP::Country::DNSBL;
  my $reg = IP::Country::DNSBL->new();

The optional argument is a DNSBL domain name (e.g. which will be appended to any country code lookup. Without this argument, the module defaults to querying


All object methods are designed to be used in an object-oriented fashion.

  $result = $object->foo_method($bar,$baz);

Using the module in a procedural fashion (without the arrow syntax) won't work.

$cc = $reg->inet_atocc(HOSTNAME)

Takes a string giving the name of a host, and translates that to an two-letter country code. Takes arguments of both the '' type and ''. If the host name cannot be resolved, returns undef. If the resolved IP address is not contained within the database, returns undef. For multi-homed hosts (hosts with more than one address), the first address found is returned.

$cc = $reg->inet_ntocc(IP_ADDRESS)

Takes a string (an opaque string as returned by Socket::inet_aton()) and translates it into a two-letter country code. If the IP address is not contained within the database, returns undef.


Only works with IPv4 addresses and ASCII hostnames.

SEE ALSO - NetOp: IP geolocation via DNS

IP::Country::Fast - uses local database for lookups.


Copyright (C) 2006, Nigel Wetters Gourlay.

NO WARRANTY. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.