/geoip

The Ruby gem for querying Maxmind.com's GeoIP database, which returns the geographic location of a server given its IP address

Primary LanguageRuby

geoip

github.com/cjheath/geoip

DESCRIPTION:

GeoIP searches a GeoIP database for a given host or IP address, and returns information about the country where the IP address is allocated, and the city, ISP and other information, if you have that database version.

FEATURES/PROBLEMS:

Includes support for ASN data files, thanks to Roland Matiz. This release adds support for timezone names, thanks to Tonni Aagesen.

SYNOPSIS:

require 'geoip'

# Use the country database:
c = GeoIP.new('GeoIP.dat').country('www.nokia.com')
=> ["www.nokia.com", "147.243.3.83", 69, "FI", "FIN", "Finland", "EU"]
c.country_code3
=> "FIN"
c.to_hash
=> {:country_code3=>"FIN", :country_name=>"Finland", :continent_code=>"EU", :request=>"www.nokia.com", :country_code=>69, :country_code2=>"FI", :ip=>"147.243.3.83"}

Returned values are the requested hostname, the IP address as a dotted quad,
Maxmind's country code, the ISO3166-1 alpha-2 country code, the ISO3166-2 alpha-3
country code, the ISO3166 country name, and the continent code.

# Use the city database:
c = GeoIP.new('GeoLiteCity.dat').city('github.com')
=> ["github.com", "207.97.227.239", "US", "USA", "United States", "NA", "CA", "San Francisco", "94110", 37.7484, -122.4156, 807, 415, "America/Los_Angeles"]
>> c.longitude
=> -122.4156
>> c.timezone
=> "America/Los_Angeles"

GeoIP.new('GeoCity.dat').city('github.com')
=> ["github.com", "207.97.227.239", "US", "USA", "United States", "NA", "CA", "San Francisco", "94110", 37.7484, -122.4156, 807, 415, "America/Los_Angeles"]

Returned values are the requested hostname, the IP address as a dotted quad,
the ISO3166-1 alpha-2 country code, the ISO3166-2 alpha-3 country code, the
ISO3166 country name, the continent code, the region (state or territory) name,
city name, postal_code/zipcode, latitude, longitude, USA DMA code, USA area code,
timezone name.

Result arrays from both city and country have mixed-in accessor methods as appropriate:
request, ip, country_code, country_code2, country_code3, country_name, continent_code,
region_name, city_name, postal_code, latitude, longitude, dma_code, area_code, timezone

GeoIP.new('GeoIPASNum.dat').asn("www.fsb.ru")
=> ["AS8342", "RTComm.RU Autonomous System"]

REQUIREMENTS:

You need one of the free GeoLite country, city or ASN databases, or a subscription database version. The last known download locations for the GeoLite database versions are <geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz>, <geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz>, <geolite.maxmind.com/download/geoip/database/asnum/GeoIPASNum.dat.gz>.

This API requires the file to be decompressed for searching. Other versions of this database are available for purchase which contain more detailed information, but this information is not returned by this implementation. See www.maxmind.com for more information.

INSTALL:

sudo gem install geoip

LICENSE:

This version Copyright © 2005 Clifford Heath Derived from the C version, Copyright © 2003 MaxMind LLC

This library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA