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

Methods

asn   city   country   each   isp   new   organization  

Classes and Modules

Class GeoIP::ASN
Class GeoIP::City
Class GeoIP::Country

Constants

VERSION = "1.1.2"   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
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

External Aliases

database_type -> databaseType

Attributes

database_type  [R]  The Edition number that identifies which kind of database you‘ve opened

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 an integer holding caching flags (unimplemented)

Public Instance methods

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

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

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.

organization(hostname)

Alias for isp

[Validate]