Class GeoIP
In: lib/geoip.rb
Parent: Object

Methods

asn   city   country   each   each_by_ip   isp   netspeed   new   organization   region  

Classes and Modules

Module GeoIP::Edition
Class GeoIP::ASN
Class GeoIP::City
Class GeoIP::Country
Class GeoIP::ISP
Class GeoIP::Region

Constants

VERSION = "1.6.4"   The GeoIP GEM version number
DATA_DIR = File.expand_path(File.join(File.dirname(__FILE__),'..','data','geoip'))   The +data/+ directory for geoip
CountryCode = YAML.load_file(File.join(DATA_DIR,'country_code.yml'))   Ordered list of the ISO3166 2-character country codes, ordered by GeoIP ID
CountryCode3 = YAML.load_file(File.join(DATA_DIR,'country_code3.yml'))   Ordered list of the ISO3166 3-character country codes, ordered by GeoIP ID
CountryName = YAML.load_file(File.join(DATA_DIR,'country_name.yml'))   Ordered list of the English names of the countries, ordered by GeoIP ID
CountryContinent = YAML.load_file(File.join(DATA_DIR,'country_continent.yml'))   Ordered list of the ISO3166 2-character continent code of the countries, ordered by GeoIP ID
RegionName = YAML.load_file(File.join(DATA_DIR,'region.yml'))   Load a hash of region names by region code
TimeZone = YAML.load_file(File.join(DATA_DIR,'time_zone.yml'))   Hash of the timezone codes mapped to timezone name, per zoneinfo
GEOIP_COUNTRY_EDITION = 1
GEOIP_CITY_EDITION_REV1 = 2
GEOIP_REGION_EDITION_REV1 = 3
GEOIP_ISP_EDITION = 4
GEOIP_ORG_EDITION = 5
GEOIP_CITY_EDITION_REV0 = 6
GEOIP_REGION_EDITION_REV0 = 7
GEOIP_PROXY_EDITION = 8
GEOIP_ASNUM_EDITION = 9
GEOIP_NETSPEED_EDITION = 10
GEOIP_COUNTRY_EDITION_V6 = 12
GEOIP_CITY_EDITION_REV1_V6 = 30
GEOIP_NETSPEED_EDITION_REV1 = 32
GEOIP_UNKNOWN_SPEED = 0   Numeric codes for NETSPEED (NETSPEED_REV1* is string-based):
GEOIP_DIALUP_SPEED = 1
GEOIP_CABLEDSL_SPEED = 2
GEOIP_CORPORATE_SPEED = 3

External Aliases

database_type -> databaseType

Attributes

database_type  [R]  The Edition number that identifies which kind of database you‘ve opened
local_ip_alias  [RW]  An IP that is used instead of local IPs

Public Class methods

Open the GeoIP database and determine the file format version.

filename is a String holding the path to the GeoIP.dat file options is a Hash allowing you to specify the caching options

Public Instance methods

Search a ASN GeoIP database for the specified host, returning the AS number and description.

Many other types of GeoIP database (e.g. userType) mis-identify as ASN type, and this can read those too.

hostname is a String holding the host‘s DNS name or numeric IP address.

Returns the AS number and description.

Source: geolite.maxmind.com/download/geoip/database/asnum/GeoIPASNum.dat.gz

Search the GeoIP database for the specified host, returning city info.

hostname is a String holding the host‘s DNS name or numeric IP address.

Returns a City object with the fourteen elements:

  • The host or IP address string as requested
  • The IP address string after looking up the host
  • The two-character country code (ISO 3166-1 alpha-2)
  • The three-character country code (ISO 3166-2 alpha-3)
  • The ISO 3166 English-language name of the country
  • The two-character continent code
  • The region name (state or territory)
  • The city name
  • The postal code (zipcode)
  • The latitude
  • The longitude
  • The USA dma_code if known (only REV1 City database)
  • The USA area_code if known (only REV1 City database)
  • The timezone name, if known

Search the GeoIP database for the specified host, returning country info.

hostname is a String holding the host‘s DNS name or numeric IP address.

If the database is a City database (normal), return the result that city would return.

Otherwise, return a Country object with the seven elements:

  • The host or IP address string as requested
  • The IP address string after looking up the host
  • The GeoIP country-ID as an integer (N.B. this is excluded from the city results!)
  • The two-character country code (ISO 3166-1 alpha-2)
  • The three-character country code (ISO 3166-2 alpha-3)
  • The ISO 3166 English-language name of the country
  • The two-character continent code

Iterate through a GeoIP city database by

Call like this, for example: GeoIP.new(‘GeoIPNetSpeedCell.dat’).each{|*a| puts("0x%08X\t%d" % a)} or: GeoIP.new(‘GeoIPv6.dat’).each{|*a| puts("0x%032X\t%d" % a)}

Search a ISP GeoIP database for the specified host, returning the ISP Not all GeoIP databases contain ISP information. Check maxmind.com

hostname is a String holding the host‘s DNS name or numeric IP address.

Returns the ISP name.

Search a GeoIP Connection Type (Netspeed) database for the specified host, returning the speed code.

hostname is a String holding the host‘s DNS name or numeric IP address.

organization(hostname)

Alias for isp

Search the GeoIP database for the specified host, returning region info.

hostname is a String holding the hosts‘s DNS name or numeric IP address.

Returns a Region object with the nine elements:

  • The host or IP address string as requested
  • The IP address string after looking up the host
  • The two-character country code (ISO 3166-1 alpha-2)
  • The three-character country code (ISO 3166-2 alpha-3)
  • The ISO 3166 English-language name of the country
  • The two-character continent code
  • The region name (state or territory)
  • The timezone name, if known

[Validate]