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
DESCRIPTION
This module gets a country and city information from ip address via www.hostip.info API.
METHODS
new
$hostip = WWW::HostipInfo->new();
$hostip = WWW::HostipInfo->new( $ip );
$hostip = WWW::HostipInfo->new( { ip => $ip, url => $url, ua => $user_agent } );
returns a WWW::HostipInfo object. This method can take an ip address or a hash reference optionally.
ip
$ip = $hostip->ip([$ip]);
setter / getter to the ip address.
url
$url = $hostip->url([$url]);
setter / getter to the HostipInfo API. Default is api.hostip.info
.
ua
$user_agent = $hostip->ua([$user_agent]);
setter / getter to the user agent. Default is LWP::UserAgent
.
get_info
$info = $hostip->get_info();
returns a WWW::HostipInfo::Info object. If the method can't get a information, will return undef
.
recent_info
$info = $hostip->get_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.
- 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, 2009-2012 by Makamaka Hannyaharamitu
This library is licensed under GNU GENERAL PUBLIC LICENSE