Using Geo to locate the IP address

2011-04-28  来源:本站原创  分类:Tech  人气:89 

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

相关文章
  • Using Geo to locate the IP address 2011-04-28

    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/dat

  • ip address check python module written anti- 2010-02-02

    Search by IP address anti-attribution to the python module business logic from the other C + + module development has been completed. #include <Python.h> #include "iplookup.h" static il_db_t _g_db; ipitem ip_lookup(const char *query) { con

  • java client for Mac according to IP address 2010-03-29

    java based IP access to the client Mac address the need for the user's ip and mac address authentication, is used here to obtain the client ip and mac address of the two methods, be retained. 1. To obtain the client ip address (this must be transmitt

  • [Quote] JSP, Servlet to obtain the real IP address of 2010-03-29

    Refers to the following article but can not receive the real ip, had the most stupid way, though it is very effective, get IP, but may run in a real environment. Please refer to attachment. <table border=1 cellspacing=0 cellpadding=0 align=center> &

  • How to use Java to get the real IP address of 2010-03-29

    How to use Java to get the real IP address of the article Category: Java programming in JSP, the access to the client's IP address is: request.getRemoteAddr (), this method in most cases are valid. However, the adoption of Apache, Squid and other sof

  • Turn: java application of the IP address of the string into an integer 2010-03-29

    A range of applications tends to be used in the registry restrictions, find IP host cities such as demand, windows of the ping command also supports the integer form of IP. 2, the key technical point IP addresses into integers as follows: 1, through

  • java to resolve host names for ip address 2010-04-02

    Today, when reading a book on the hands-on examples of knock program written by java can be resolved by entering the host name to its ip address import java.net.*; /** * Resolve the host name to obtain an IP address */ public class GetIp { public sta

  • Access to the real IP address of the client 2010-04-15

    We know that in JSP, the web client to obtain IP address is: request.getRemoteAddr (), this method in most cases are valid. However, the adoption of Apache, Squid and other software, can not get the reverse proxy to the client's real IP address. If y

  • Enter the IP address can be automatically changed at least three text boxes 2009-02-19

    function mask (obj) ( obj.value = obj.value.replace (/ [^ \ d] / g,'') key1 = event.keyCode if (key1 == 37 | | key1 == 39) ( obj.blur (); nextip = parseInt (obj.name.substr (obj.name.length-1, 1)) nextip = key1 == 37? nextip-1: nextip +1; nextip = ne

  • Under Linux access to the machine IP address of 2008-08-10

    Can use the following code: InetAddress inet = InetAddress.getLocalHost(); System.out.println(" A native of ip=" + inet.getHostAddress()); In the window below to work. In the Linux return 127.0.0.1. Mainly in linux to return to the / etc / hosts

  • IP address and a long integer conversion between Xiangjie 2010-03-23

    Today, finally get to know the ip address and the conversion between integers, in the here and share with you their experience nagging one. Event Causes: Through the ip address used in the project to obtain a city name, like the original code a searc

  • IP address and Integer type Hu Zhuan 2010-03-24

    import java.net.InetAddress; import java.net.UnknownHostException; public class TypeConversionUtil { /** * IP Address to integer type * convert ipaddr like 1.1.1.1 to int * @param str * @return */ public static int convertString2Ipaddr(String str){ i

  • Enter IP address can be automatically changed over the three text boxes 2010-03-13

    function mask (obj) ( obj.value = obj.value.replace (/ [^ \ d] / g,'') key1 = event.keyCode if (key1 == 37 | | key1 == 39) ( obj.blur (); nextip = parseInt (obj.name.substr (obj.name.length-1, 1)) nextip = key1 == 37? nextip-1: nextip +1; nextip = ne

  • Access to the machine with python ip address 2010-02-02

    #!/usr/bin/python #coding=utf-8 import socket import fcntl import struct def get_ip_address(ifname): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) return socket.inet_ntoa(fcntl.ioctl( s.fileno(), 0x8915, # SIOCGIFADDR struct.pack('256s', ifnam

  • Flex IP address to obtain the current service 2010-03-10

    var uri: URI = new URI (Application.application.url); trace (uri.authority); / / IP address of the server which hosts this flex application trace (uri.port); trace (uri.path); var uri: URI = new URI (Application.application.url); userService.url = "h

  • ip address, subnet mask, gateway 2010-03-16

    ip address is divided into: (Ip address, including network and host addresses) 1-126 is a class A address, seven network number (ie network address), start with 0 128-191 is B class address, 14-bit network number, with 10 Start 192-223 is C class add

  • Tencent's IP address query interface (JS) 2010-03-22

    Tencent's IP address query interface (JS) Tencent's IP address query interface is good, IP address of query accuracy is high, IP address lookup is also easy to use, this is coming from elsewhere reproduced, the test found a small BUG, IP address look

  • centos changes IP address, gateway, DNS 2010-03-01

    1, CentOS IP address changes Modify the network card IP address corresponding to the configuration file # Vi / etc/sysconfig/network-scripts/ifcfg-eth0 Changes following DEVICE = eth0 # describe the corresponding network card device alias, such as if

  • ASP.NET to get the client IP address 2010-02-05

    ASP.NET to get the client IP address approach: Method 1: Request.UserHostAddress.ToString (). Trim (); Method 2: Request.ServerVariables ["REMOTE_ADDR"];

  • java applet web server automatically reports the public network IP address 2010-04-05

    Companies take a SVN server, because there is no fixed IP address. Note the IP to the company e-mail serve, and come home to connect to the server through this IP, IP not found. So one way to write a small program, which the server automatically dete