| Path: | README |
| Last Update: | Tue Mar 04 23:58:45 +0100 2008 |
This is a library which provides a single function. The function takes as input an IP address and it outputs a hash containing best-guess geographical information (like city, country, latitude, and longitude).
Actually this is only a Ruby binding to a C library which provides this function. Also, you must download a large binary database with all this mapping information. It is kindly provided free of charge by MaxMind.com.
require 'geoip_city'
db = GeoIPCity::Database.new('/opt/GeoIP/share/GeoIP/GeoLiteCity.dat')
result = db.look_up('24.24.24.24')
p result
# => {:city=>"Ithaca",
# :latitude=>42.4277992248535,
# :longitude=>-76.4981994628906,
# :country_code3=>"USA",
# :country_code=>"US",
# :country_name=>"United States",
# :dma_code=>555,
# :area_code=>607,
# :region=>"NY" }
There are two optional arguments to database initializer. The first argument is the filename of the GeoIPCity.dat file The second argument (optional) is to specify how GeoIP should keep the database in memory. There are three possibilities
The third argument is boolean and decides whether the system should reload the database if changes are made to the dat file. (You probably don‘t need this. Default: false.)
For example
GeoIPCity::Database.new(dbfile, :filesystem, true)
Some variation of the following should work.
tar -zxvf GeoIP-1.4.3.tar.gz cd GeoIP-1.4.3 ./configure --prefix=/opt/GeoIP make && sudo make install
sudo gem install geoip_city -- --with-geoip-dir=/opt/GeoIP
Copyright (C) 2007 Ryan Dahl (ry@tinyclouds.org)
I give permission for you to do whatever you‘d like to do with this software.