Create your blog and photo album with postbit
Create your blog and photo album

Create new post

Content:

Upload a picture:
Tags (keywords separated by comma)

Save Cancel
webtools:   Followers: 10 ; Following: 2

Explore webtools's photo albums:
Photos from posts (2)
Photos from posts (2)

GeoIP - locating IP country and city



GeoIP2 Precision give more city results that were not available in free version.

For example, the GeoIP2 Precision says that IP "200.153.229.61" is from the city Ipero, region Sao Paulo, Brazil, ISP and Organization "virtua" (domain virtua.com.br), postal code 18560, coordinates (-23.35, -47.6833).
You can test individual IP's using the geoip demo page: https://www.maxmind.com/en/geoip-demo

And the free version only finds the country (Brazil).

Free GeoIP database download:
http://dev.maxmind.com/geoip/geoip2/geolite2/
GeoLite2 City (GeoLite2-City.mmdb and .csv)
GeoLite2 Country (GeoLite2-Country.mmdb and .csv)

Sample content of GeoLite2-City-Blocks.csv (first line is header with file format / file structure and following lines are sample data). Size of complete file is 182 Mb:
network_start_ip,network_prefix_length,geoname_id,registered_country_geoname_id,represented_country_geoname_id,postal_code,latitude,longitude,is_anonymous_proxy,is_satellite_provider
::ffff:1.0.64.0,114,1862415,1861060,,,34.3963,132.4594,0,0
::ffff:1.0.32.0,115,1809858,1814991,,,23.1167,113.2500,0,0
::ffff:1.0.16.0,116,1850147,1861060,,,35.6850,139.7514,0,0
 
Sample content of GeoLite2-City-Locations.csv (first line is header / file structure). Size of complete file is 6.4 Mb:
geoname_id,continent_code,continent_name,country_iso_code,country_name,subdivision_iso_code,subdivision_name,city_name,metro_code,time_zone
1862415,AS,Asia,JP,Japan,34,Hiroshima,Hiroshima,,Asia/Tokyo
1809858,AS,Asia,CN,China,44,Guangdong,Guangzhou,,Asia/Shanghai
1850147,AS,Asia,JP,Japan,13,"Tōkyō",Tokyo,,Asia/Tokyo
 
 
Other GeoIP database (samples):
https://github.com/maxmind/geoip-api-php/tree/master/tests/data
Available sample files to download:
 
GeoIP.dat
GeoIPASNum.dat
GeoIPCity.dat
GeoIPDomain.dat
GeoIPISP.dat
GeoIPNetSpeedCell.dat
GeoIPOrg.dat
GeoIPRegion.dat
GeoIPv6.dat
GeoLiteCityIPv6.dat
 
The full GeoIP Organization (ISP list) costs $25: https://www.maxmind.com/en/organization
The full GeoIP2 City database costs $370: https://www.maxmind.com/en/city
 
I downloaded the binary files (free version):
GeoIP.dat (719 kb, contains only country code data) and GeoLiteCity.dat (18 MB, contains country, region and city information)
 
Note that some IPs can not be found, not even in the Geo IP Precision database.
Example: "The IP address you provided (91.210.101.92) cannot be found in our database." (error from maxmind demo site)
 

How to install Geo::IP (installing and using perl Geo::IP CPAN module):

1) Download Geo IP databases:

 Download page 'GeoLite Country' with updated version of GeoIP.dat.gz:
 http://dev.maxmind.com/geoip/legacy/geolite/
 wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
 wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
 
 gunzip GeoIP.dat.gz; gunzip GeoLiteCity.dat.gz;
 mkdir /usr/local/share/GeoIP
 ln -s GeoIP.dat /usr/local/share/GeoIP/GeoIP.dat
 
GEOIP TEST SCRIPT (returns country code, 2 letters):
/usr/local/bin/geoip-lookup (IP number)
 
2) Download and install C API (CAPI):
wget http://www.maxmind.com/download/geoip/api/c/GeoIP-1.6.0.tar.gz
 ./configure
 make
 make install
 
3) install Geo::IP perl module from CPAN:
# Not needed: Geo::IP::PurePerl
# If you ge the error "The GeoIP CAPI is not installed you should do that", then install manually. Type in CPAN prompt:
look Geo::IP
cd (path to Geo::IP downloaded source)
perl Makefile.PL LIBS='-L/usr/local/lib' INC='-I/usr/local/include';
make
make test
make install
 
If you get the error:  "fatal error: GeoIP.h: No such file or directory", then you need to install the Geo IP C API (CAPI) in step 2 above, because it contains the required libs to compile Geo::IP.

Post by webtools (2014-08-29 12:22)

Post your comment:

Name: Email: Site:




| Explore users | New posts | Create your blog | Create your photo album |
| About Postbit | Our blog | Terms of use | Contact Postbit |


Copyright © 2018 - postbit.com