Using Geo to locate the IP address
>cpan
cpan>install Geo::IP::PurePerl
my examples are here: /root/.cpan/build/Geo-IP-PurePerl-1.25-yvkM42/t
# fetch latest GeoIP database, updated monthly
>wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
>gunzip GeoIP.dat.gz
>mkdir /usr/local/share/GeoIP
>mv GeoIP.dat /usr/local/share/GeoIP/GeoIP.dat
>chmod a+x /usr/local/share/GeoIP/GeoIP.dat
Geo::IP::PurePerl method
my $gi = Geo::IP::PurePerl->open("/usr/local/share/GeoIP/GeoIP.dat", GEOIP_STANDARD);
my $clientIp = $ENV{REMOTE_ADDR};
my $countryCode = $gi->country_code_by_name( $clientIp );
my $countryName = $gi->country_name_by_addr( $clientIp );
my $ispName = $gi->isp_by_addr($clientIp);
@data = $gi->get_city_record($clientIp);
my $record_str = join "," , @data;
my $q = CGI->new;
my $actionName = $q->param('actionName');
my $vars = {
clientIp => $clientIp,
countryCode => $countryCode,
countryName => $countryName,
records => $record_str,
ispName => $ispName,
remoteHost => $ENV{REMOTE_HOST},
remotePort => $ENV{REMOTE_PORT},
remoteUser => $ENV{REMOTE_USER},
callingPage => $ENV{HTTP_REFERER},
requestMethod => $ENV{REQUEST_METHOD},
hostServerAddress => $ENV{HTTP_HOST},
requestURI => $ENV{REQUEST_URI},
userAgent => $ENV{HTTP_USER_AGENT},
actionName => $actionName,
};
references:
http://www.maxmind.com/app/perl
http://cpan.uwinnipeg.ca/htdocs/Geo-IP-PurePerl/Geo/IP/PurePerl.html
分享到:
相关推荐
标题 "Locate IP Address Lookup Show on Map City by JavaScript" 暗示了我们要讨论的是一个使用JavaScript实现的项目,该项目能够定位用户的IP地址,并在地图上显示其所在的城市。这个功能常见于许多网站,用于...
Spark在windows运行报错-ERROR Shell Failed to locate the winutils binary in the hadoop binary path java.io-附件资源
This book focuses on the tips and techniques used to identify the symptoms and determine possible causes of lousy network performance using Wireshark, the world's most popular network analyzer.Join ...
MSP430 Microcontroller Basics....should be able to locate the material unless it has vanished completely. I do not repeat the application notes, which are mentioned throughout the text.
The attached code shows how to locate files in a directory using the FileSystemObject. You can search just within the specified directory or include all subdirectories in the search.
使用assembly插件打包jar后启动时,总是出现Unable to locate Spring NamespaceHandler for XML schema....错误,网上找了各种方法都没有用,在尝试了100+失败后,解决了这个问题,在打包的jar中,META-INF目录下,...
一个hapi插件来对请求进行地理定位··· 关注以获取更新...=16 hapi >=8安装将hapi-geo-locate添加为项目的依赖项: npm i hapi-geo-locate使用hapi v17或v18? 使用3.x发行版: npm i hapi-geo-locate@3您是否使用hap
The packet switch uses the destination IP address in the packet to determine the outgoing link. Asking which road to take is analogous to a packet asking which outgoing link it should be forwarded on...
标题 "FlexBuilder运行项目报Flex Builder cannot locate the required version of Flash Player" 描述了一个常见的问题,即在使用FlexBuilder开发Flex应用程序时,由于找不到合适的Flash Player版本,导致项目无法...
In the present paper the use of ATI/DPCA is extended in order to detect and geo-locate all observable moving targets in the Gotcha challenge data, including both the scripted movers and targets of ...
Over 100 recipes to analyze and troubleshoot network problems using Wireshark 2 This book contains practical recipes on troubleshooting a data communications network. This second version of the book ...
use the android to locate the magnet, a project of Android Studio that use the android phone to locate a magenet. the position of the magnet has been packaged to messages. video: blog: e-mail:/...
For a process to access 3 GB of address space, the executable image must have been linked with the /LARGEADDRESSAWARE flag or modified using Imagecfg.exe. It should be pointed out that SQL Server was ...
results = [locate_ip(ip) for ip in ips_to_locate] for result in results: print(result) ``` 5. 存储和更新数据库 为了保持IP数据库的时效性,你需要定期更新`.dat`文件。这通常需要到纯真IP数据库的官方网站...
selenium+firefox在定位时遇到selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: 由于是js加载页面,想确认是否是js的原因,随后进行多次调试时发现“//div”竟然也出现了...
在Linux系统中,GCC(GNU Compiler Collection)是一个关键的开源工具链,用于编译C、C++、Fortran、Objective-C等编程语言的源代码。它不仅包括了编译器,还包括预处理器、链接器和其他相关工具。...
2. 配置IP核:使用IP Integrator来添加、配置所需的IP核。IP核可以通过图形界面拖放的方式进行配置,可以定义端口的类型、数量和功能等。 3. 连接IP核:配置好各个IP核后,需要对它们进行连接。IP Integrator提供了...