The geoip database of maxmind can accurately obtain the user's geographic location information based on the user's IP address. Firefox uses it to calculate the region where the user is downloaded.
It mainly includes two data files stored in key-value mode, GEO country and geo ip. If you only focus on country information, you can use a much smaller GEO country database.
Both databases are divided into commercial and free versions, with an accuracy rate above 99.5%. For most applications, free versions are sufficient.
Geoip clients include the following languages:
C library
Perl Module
PHP Module
Apache module (mod_geoip)
Java class
Python class
C # class
Ruby Module
Ms com Object
VB. NET
Pascal
Javascript
The following uses Perl as an example to describe how to use it.
Download the geolitecountry or geolitecity data file (http://www.maxmind.com/app/geolitecountryor http://www.maxmind.com/app/geolitecity ). The file size of geolitecountry is about 1 m, while that of geolitecountry is about 43 m.
The geoip module of Perl mainly consists of two GEO: IP and GEO: IP: pureperl. The previous one calls the C language implementation, which is more efficient than the previous pure Perl implementation module.
The following code analyzes IP country information:
Use GEO: IP; </P> <p> my $ gi = GEO: IP-> New (geoip_standard ); <br/> my $ Country = $ Gi-> country_code_by_addr ("24.24.24.24") | 'no record '; </P> <p> Print "country: $ country/N "; <br/>
Output:
Country: US
The following code analyzes the details of an IP Address:
Use GEO: IP; </P> <p> my $ gi = <br/> GEO :: IP-> open ("/usr/local/share/geoip/geolitecity. dat ", geoip_standard); </P> <p> my $ r = $ Gi-> record_by_name (" 134.153.33.202 ") | 'no record '; </P> <p> Print join ("--", <br/> $ R-> country_code, $ R-> country_code3, $ R-> region, $ R-> region_name, $ R-> city, <br/> $ R-> postal_code, $ R-> latitude, $ R-> longpolling); <br/>
Output:
CA--CAN--NL -- Newfoundland-Saint John's ---- 47.5500 --- 52.6667
You can see that this user is from St. John's district in newfenghua, Canada.
Based on the statistics of the number of users in batches, we can analyze the key user regions and marketing results as an example, from which we can see the changing trend of the number of foreign users.