WWW::HostipInfo - get a country and city information from ip address via www.hostip.info API.
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
This module gets a country and city information from ip address via www.hostip.info API.
$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 = $hostip->ip([$ip]);
setter / getter to the ip address.
$url = $hostip->url([$url]);
setter / getter to the HostipInfo API. Default is api.hostip.info.
api.hostip.info
$user_agent = $hostip->ua([$user_agent]);
setter / getter to the user agent. Default is LWP::UserAgent.
LWP::UserAgent
$info = $hostip->get_info();
returns a WWW::HostipInfo::Info object. If the method can't get a information, will return undef.
undef
returns a WWW::HostipInfo::Info object.
WWW::HostipInfo::Info
With get_info(), WWW::HostipInfo object returns WWW::HostipInfo::Info object.
get_info()
getters for informations.
return the cuntry code. If private ip address is used, the code is 'XX'.
an alias to country_code
return the cuntry name.
an alias to country_name
return the city name as long as it is not unknown.
return state code if the coutnry is US.
If private ip address is used, returns true.
If the object has no data for city, returns true.
If the object has no data for country, returns true.
http://www.hostip.info/, LWP
Makamaka Hannyaharamitu, <makamaka[at]cpan.org>
Copyright 2005, 2009-2012 by Makamaka Hannyaharamitu
This library is licensed under GNU GENERAL PUBLIC LICENSE
To install WWW::HostipInfo, copy and paste the appropriate command in to your terminal.
cpanm
cpanm WWW::HostipInfo
CPAN shell
perl -MCPAN -e shell install WWW::HostipInfo
For more information on module installation, please visit the detailed CPAN module installation guide.