NAME
WWW::HostipInfo - get a country and city information from ip address via www.hostip.info API.
SYNOPSIS
use WWW::HostipInfo;
my $hostip = new WWW::HostipInfo;
my $ip = 'xxx.xxx.xxx.xxx';
my $info = $hostip->get_info($ip);
if($info->is_private){ warn "This is a private ip address." }
my $country_code = $info->code;
my $city_name = $info->city;
my $region = $info->region; # if any
$info = $hostip->recent_info->country_name; # fetch most recent data
print WWW::HostipInfo->new($ip)->get_info->city; # shortcut
$info = $hostip->guess($info->ip) if( $info->has_unknown_city );
DESCRIPTION
This module gets a country and city information from ip address via www.hostip.info API.
METHODS
- new
-
returns a WWW::HostipInfo object. This method can take ip address optionally.
- ip([$ip])
-
setter / getter to ip address.
- get_info
-
returns a WWW::HostipInfo::Info object. If the method can't get a information, will return
undef
. - guess([$ip])
-
returns a WWW::HostipInfo object. If the original city is unknown, returns a guessed infomation. When the argument was not set, most recent data is used.
- recent_info
-
returns a WWW::HostipInfo::Info object.
WWW::HostipInfo::Info
With get_info()
, WWW::HostipInfo object returns WWW::HostipInfo::Info object.
METHODS
getters for informations.
- country_code
-
return the cuntry code. If private ip address is used, the code is 'XX'.
- code
-
an alias to country_code
- country_name
-
return the cuntry name.
- name
-
an alias to country_name
- country
-
an alias to country_name
- city
-
return the city name as long as it is not unknown.
- region
-
return state code if the coutnry is US.
- latitude
- longitude
- ip
- is_private
-
If private ip address is used, returns true.
- is_guessed
-
If the object has any guessed data, returns true.
- has_unknown_city
-
If the object has no data for city, returns true.
- has_unknown_country
-
If the object has no data for country, returns true.
SEE ALSO
AUTHOR
Makamaka Hannyaharamitu, <makamaka[at]cpan.org>
COPYRIGHT AND LICENSE
Copyright 2005 by Makamaka Hannyaharamitu
This library is licensed under GNU GENERAL PUBLIC LICENSE