NAME
Geo::IP2Location - Lookup of country, region, city, latitude, longitude, ZIP code, time zone, ISP, domain name, connection type, IDD code, area code, weather station code and station, MCC, MNC, mobile carrier brand name, elevation, usage type, IP address type, advertising category, district, AS number and AS name by using IP address. It supports both IPv4 and IPv6 addressing. Please visit IP2Location Database for more information.
SYNOPSIS
use Geo::IP2Location;
eval {
my $obj = Geo::IP2Location->open("IP-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE-TIMEZONE-ISP-DOMAIN-NETSPEED-AREACODE-WEATHER-MOBILE-ELEVATION-USAGETYPE-ADDRESSTYPE-CATEGORY-DISTRICT-ASN.BIN");
if (!defined($obj)) {
print STDERR Geo::IP2Location::get_last_error_message();
}
my $dbversion = $obj->get_database_version();
my $moduleversion = $obj->get_module_version();
my $countryshort = $obj->get_country_short("2001:1000:0000:0000:0000:0000:0000:0000");
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 $iddcode = $obj->get_iddcode("20.11.187.239");
my $areacode = $obj->get_areacode("20.11.187.239");
my $weatherstationcode = $obj->get_weatherstationcode("20.11.187.239");
my $weatherstationname = $obj->get_weatherstationname("20.11.187.239");
my $mcc = $obj->get_mcc("20.11.187.239");
my $mnc = $obj->get_mnc("20.11.187.239");
my $brand = $obj->get_mobilebrand("20.11.187.239");
my $elevation = $obj->get_elevation("20.11.187.239");
my $usagetype = $obj->get_usagetype("20.11.187.239");
my $addresstype = $obj->get_addresstype("20.11.187.239");
my $category = $obj->get_category("20.11.187.239");
my $district = $obj->get_district("20.11.187.239");
my $asn = $obj->get_asn("20.11.187.239");
my $as = $obj->get_as("20.11.187.239");
my $asdomain = $obj->get_as_domain("20.11.187.239");
my $asusagetype = $obj->get_as_usagetype("20.11.187.239");
my $ascidr = $obj->get_as_cidr("20.11.187.239");
($cos, $col, $reg, $cit, $lat, $lon, $zip, $tmz, $isp, $dom, $ns, $idd, $area, $wcode, $wname, $mcc, $mnc, $brand, $elevation, $usagetype, $addresstype, $category, $district, $asn, $as, $asdomain, $asusagetype, $ascidr) = $obj->get_all("20.11.187.239");
($cos, $col, $reg, $cit, $lat, $lon, $zip, $tmz, $isp, $dom, $ns, $idd, $area, $wcode, $wname, $mcc, $mnc, $brand, $elevation, $usagetype, $addresstype, $category, $district, $asn, $as, $asdomain, $asusagetype, $ascidr) = $obj->get_all("2001:1000:0000:0000:0000:0000:0000:0000");
$obj->close();
} or do {
print STDERR Geo::IP2Location::get_last_error_message();
};
DESCRIPTION
This Perl module provides a fast and simple way to look up geolocation and network information for an IP address using an IP2Location BIN database.
It allows you to retrieve a wide range of data using IPv4 and IPv6 addresses, including:
a) Geolocation: Country, Region, City, Latitude, Longitude, ZIP Code, Time Zone, District, Elevation
b) Network: ISP, Domain Name, Connection Type, IP Address Type, Usage Type
c) Carrier Information: Mobile Country Code (MCC), Mobile Network Code (MNC), Mobile Carrier Brand
d) Autonomous System (AS): AS Number, AS Name, AS Domain Name, AS Usage Type, AS CIDR
e) Additional Data: IDD Code, Area Code, Weather Station Code, Weather Station Name, IAB Advertising Category
This module can be used in many types of project such as:
1) Selecting the geographically closest mirror for content delivery.
2) Analyzing web server logs to determine the countries of your visitors.
3) Detecting and preventing credit card fraud.
4) Implementing software export controls.
5) Displaying native languages and currencies to users.
6) Preventing password sharing and service abuse.
7) Geotargeting content and advertisements.
To ensure high accuracy, the commercial databases are updated on a daily, weekly or semi-monthly basis.
IP2LOCATION DATABASES
Commercial Databases: The complete, high-accuracy databases are available via paid subscription at IP2Location.com. Free LITE Database: A free, Creative Commons licensed database is available with sign-up at IP2Location LITE Page. Sample Database: A free sample DB1 database is included in the /samples directory of this distribution or can be downloaded from the IP2Location development libraries page.
CLASS METHODS
- $obj = Geo::IP2Location->open($database_file);
-
Constructs a new Geo::IP2Location object with the database located at $database_file.
OBJECT METHODS
- $countryshort = $obj->get_country_short( $ip );
-
Returns the ISO 3166 country code for the given IP address or domain name, or a hyphen (-) for unassigned or private addresses.
- $countrylong = $obj->get_country_long( $ip );
-
Returns the full country name for the given IP address or domain name, or a hyphen (-) for unassigned or private addresses.
- $region = $obj->get_region( $ip );
-
Returns the region name for the given IP address or domain name.
- $city = $obj->get_city( $ip );
-
Returns the city name for the given IP address or domain name.
- $latitude = $obj->get_latitude( $ip );
-
Returns the latitude for the given IP address or domain name.
- $longitude = $obj->get_longitude( $ip );
-
Returns the longitude for the given IP address or domain name.
- $isp = $obj->get_isp( $ip );
-
Returns the ISP name for the given IP address or domain name.
- $domain = $obj->get_domain( $ip );
-
Returns the domain name for the given IP address or domain name.
- $zip = $obj->get_zipcode( $ip );
-
Returns the ZIP code for the given IP address or domain name.
- $tz = $obj->get_timezone( $ip );
-
Returns the time zone for the given IP address or domain name.
- $ns = $obj->get_netspeed( $ip );
-
Returns the connection type (DIAL, DSL or COMP) for the given IP address or domain name.
- $idd = $obj->get_iddcode( $ip );
-
Returns the country IDD calling code for the given IP address or domain name.
- $area = $obj->get_areacode( $ip );
-
Returns the phone area code code for the given IP address or domain name.
- $wcode = $obj->get_weatherstationcode( $ip );
-
Returns the nearest weather station code for the given IP address or domain name.
- $wname = $obj->get_weatherstationname( $ip );
-
Returns the nearest weather station name for the given IP address or domain name.
- $mcc = $obj->get_mcc( $ip );
-
Returns the mobile carrier code (MCC) for the given IP address or domain name.
- $mnc = $obj->get_mnc( $ip );
-
Returns the mobile network code (MNC) for the given IP address or domain name.
- $brand = $obj->get_mobilebrand( $ip );
-
Returns the mobile carrier brand name for the given IP address or domain name.
- $elevation = $obj->get_elevation( $ip );
-
Returns the elevation for the given IP address or domain name.
- $usagetype = $obj->get_usagetype( $ip );
-
Returns the usage type for the given IP address or domain name.
- $addresstype = $obj->get_addresstype( $ip );
-
Returns the IP address type (A-Anycast, B-Broadcast, M-Multicast & U-Unicast) for the given IP address or domain name.
- $category = $obj->get_category( $ip );
-
Returns the IAB content taxonomy category name for the given IP address or domain name.
- $district = $obj->get_district( $ip );
-
Returns the district name for the given IP address or domain name.
- $asn = $obj->get_asn( $ip );
-
Returns the autonomous system (AS) number for the given IP address or domain name.
- $as = $obj->get_as( $ip );
-
Returns the name of the autonomous system (AS) for the given IP address or domain name.
- $asdomain = $obj->get_as_domain( $ip );
-
Returns the domain name of the autonomous system (AS) for the given IP address or domain name.
- $asusagetype = $obj->get_as_usagetype( $ip );
-
Returns the usage type associated with the autonomous system (AS) for the given IP address or domain name.
- $ascidr = $obj->get_as_cidr $ip );
-
Returns the CIDR associated with the autonomous system (AS) for the given IP address or domain name.
- ($cos, $col, $reg, $cit, $lat, $lon, $zip, $tmz, $isp, $dom, $ns, $idd, $area, $wcode, $wname, $mcc, $mnc, $brand, $elevation, $usagetype, $addresstype, $category, $district, $asn, $as, $asdomain, $asusagetype, $ascidr) = $obj->get_all( $ip );
-
Returns an array of country, region, city, latitude, longitude, ZIP code, time zone, ISP, domain name, connection type, IDD code, area code, weather station code and station, MCC, MNC, mobile carrier brand, elevation, usage type, address type, IAB advertising category, district name, AS number, AS name, AS domain name, AS usage type, and AS CIDR for a given IP address.
- $dbversion = $obj->get_database_version();
-
Returns the version number of database.
- $moduleversion = $obj->get_module_version();
-
Returns the version number of Perl module.
- $error = Geo::IP2Location::get_last_error_message();
-
Returns the last error message.
SEE ALSO
VERSION
8.80
AUTHOR
Copyright (c) 2025 IP2Location.com
All rights reserved. This package is free software. It is licensed under the MIT. See the LICENSE file for full license information.