DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

IP2Location Perl Module

01.19.2010
| 3515 views |
  • submit to reddit
        IP2Location Perl Module is a pure Perl API to support all IP2Locationâ„¢ database products. This API is meant to allow easy integration between your program written in Perl and 
the IP2Location Binary (.BIN) data file which will allow you to query the data for information like Country, Region, City, ISP, Latitude, Longitude, Domain, ZIP code, Time zone, ISP, Domain name, Connection type, Area Code and Weather station code.  It has been optimized for speed and memory utilization. Developers can use the API to query all IP2Locationâ„¢ binary databases for applications written in Perl. Please visit http://www.ip2location.com/perl.aspx for the perl module download and database download. Get more geolocation information at http://www.ip2location.com .

use Geo::IP2Location;
$obj = Geo::IP2Location->open("IP-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ISP-DOMAIN.BIN");

my $countryshort = $obj->get_country_short("20.11.187.239");
my $countrylong = $obj->get_country_long("20.11.187.239");
my $region = $obj->get_region("20.11.187.239");
my $city = $obj->get_city("20.11.187.239");
my $latitude = $obj->get_latitude("20.11.187.239");
my $longitude = $obj->get_longitude("20.11.187.239");
my $isp = $obj->get_isp("20.11.187.239");
my $domain = $obj->get_domain("20.11.187.239");
my $zipcode = $obj->get_zipcode("20.11.187.239");
my $timezone = $obj->get_timezone("20.11.187.239");
my $netspeed = $obj->get_netspeed("20.11.187.239");
my ($countryshort, $countrylong, $region, $city, $latitude, $longitude, $zipcode, $timezone, $isp, $domain, $netspeed) = $obj->get_all("20.11.187.239");