• Stars
    star
    714
  • Rank 63,413 (Top 2 %)
  • Language
    Ruby
  • License
    GNU Lesser Genera...
  • Created over 15 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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:¶ ↑

Does not support the new Maxmind v2 database formats.

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

If you have required ‘io/extra’ and have IO#pread, cross-process file-descriptor sharing is enabled. Each GeoIP instance keeps the file descriptor open, with a Mutex for thread-safety. You should consider this if your process will fork without exec, as modrails does

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"]

# Use the city ipv6 database:
GeoIP.new('GeoLiteCityv6.dat').city('::151.38.39.114')
=> ["::151.38.39.114", "::151.38.39.114", "IT", "ITA", "Italy", "EU", "05", "Piacenza", "", 45.016699999999986, 9.666699999999992, nil, nil, "Europe/Rome"]

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"]

For testing or other purposes, you might wish to treat localhost IP addresses as some other address - an external one. You can do this by assigning the desired external IP address to the attribute local_ip_alias:

g = GeoIP.new('GeoIP.dat')
g.city("127.0.0.1")
=> nil
g.local_ip_alias = "173.194.112.35"
g.city("127.0.0.1") 
#<struct GeoIP::City request="127.0.0.1", ip="173.194.112.35", country_code2="US", country_code3="USA", country_name="United States", continent_code="NA", region_name="CA", city_name="Mountain View", postal_code="94043", latitude=37.41919999999999, longitude=-122.0574, dma_code=807, area_code=650, timezone="America/Los_Angeles", real_region_name="California">

REQUIREMENTS:¶ ↑

You need one of the free GeoLite country, city or ASN binary databases, or a subscription database version. Maxmind have unfortunately stopped updating databases in the original GeoLite format - only v2 is currently available, and the CSV form. There is no available compiler from CSV to the legacy database format, so this gem has started to go stale and needs a path forwards. Any volunteers? The download location for the GeoLite2 databases is <dev.maxmind.com/geoip/geoip2/geolite2/>.

This API requires a gzipped binary file to be decompressed for searching. Other versions of this database are available for purchase which contain more detailed information, but not all this information is 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 Lesser 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 follows the license applied by Maxmind to their C library, for example in the version here: <www.maxmind.com/download/geoip/api/c/GeoIP-1.4.2.tar.gz>.

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 Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

More Repositories

1

activefacts

A fact-based semantic modeling and query language (CQL) and application runtime (the Constellation API)
Ruby
54
star
2

polyglot

Augment 'require' to load non-ruby file types
JavaScript
49
star
3

Raphaelle

Drag and drop for Raphaël objects
JavaScript
32
star
4

jquery.comet

A Comet (Bayeux) Plugin for JQuery, with an async_sinatra server
JavaScript
27
star
5

AdventureWorks

The Microsoft AdventureWorks database as a fact-based model in CQL and ORM
HTML
22
star
6

stm32f3-discovery-usb-example

The STM32F3-Discovery USB example, modified for compilation with GCC. This implements a USB Joystick using the accelerometers
C
17
star
7

AD9959

AD9959 4-channel Direct Digital Synthesis Arduino Library
C++
13
star
8

sinatra_omniauth

A Sinatra extension that provides pure OmniAuth goodness to your application (with DataMapper)
Ruby
11
star
9

strpp

C++ Unicode library for Array and String, Regexp and PEG parsing, using ref-counted slices with value semantics
C++
9
star
10

adl

Aspect Definition Language. A powerful and succinct replacement for XML, JSON, YAML, etc.
C#
9
star
11

bayeux-rack

Bayeux (COMET) long-polling server-side protocol implementation in async_sinatra for Thin
Ruby
8
star
12

jquery.key

Uniform key handling for DOM keyboard events
JavaScript
7
star
13

powerscan

Radio spectrum scanner based on SoapySDR and FFTW
C
6
star
14

math.random.js

A better random number generator for Javascript, and add-ons
JavaScript
6
star
15

activefacts-api

A fact-based data model DSL and API
Ruby
6
star
16

restart

A new more flexible approach to REST, that doesn't cripple it to HTTP
5
star
17

dfu-util

Device Firmware Upgrade Utilities
C
4
star
18

activefacts-examples

Example models in the Constellation Query Language for use with ActiveFacts. Includes generated files,
Ruby
4
star
19

AD9851LCD

Radio Frequency Signal generator, using an Arduino with a TFT Touchscreen and an AD9851
C++
4
star
20

semper

HAML/Jade/Slim-style micro-templating in Javascript
JavaScript
4
star
21

dso-firmware

My fork of http://gitorious.org/dsonano/dso-firmware to add a 2nd oscilloscope channel for XY mode
C
4
star
22

audiograph

Audio spectrum display. Capture audio using portaudio, analyse the spectrum using fftw3, and display using gl/gosu, all in realtime
Ruby
4
star
23

facetious

A Faceted search extension for ActiveRecord using SQL
Ruby
3
star
24

loggingproxy

A TCP (or HTTP) proxy with logging features
Ruby
3
star
25

wifi_credential_ui

LVGL: Display available WiFi Access Points, select one, receive and save credentials
C++
3
star
26

wrocksim

A Water Rocket simulator written entirely in Javascript
JavaScript
3
star
27

onewire

Wrapper API for the Dallas One-Wire interface library
C
3
star
28

wbxml

Ruby bindings for wbxml library (http://libwbxml.aymerick.com)
Ruby
3
star
29

RFDocuments

Collected third-party documents for radio frequency designs, copyrights to original authors.
C
3
star
30

mar

MS/DOS FAT12 archiver (ala tar)
C
3
star
31

car

CP/M Archiver (c.f. tar but for CP/M volumes)
C
3
star
32

esp32lcd

A development board for the ESP32 with a 2.4" touchscreen LCD
XSLT
3
star
33

AD9851

Arduino library to control the AD9851 Direct Digital Synthesis (DDS) chip or module.
C++
3
star
34

lvgl_test

Project to test ESP32 and ESP-IDF development on LVGL
C++
2
star
35

SigGen

Arduino Nano, TFT LCD Touch screen, AD9851
2
star
36

pegex

Regular PEGs - like regular expressions but prefix notation and possessive behaviour - in C(++)
C++
2
star
37

lvgl_touchscreen_cal

A calibration screen for touchscreen geometry to work with LVGL v8
C
2
star
38

activefacts-metamodel

Core meta-model for fact-based models (schema)
Ruby
2
star
39

EagleLibrary

My library of components for use with the EAGLE schematic and circuit-board editor
1
star
40

date-constructor

Add flexible constructors to Ruby's Date and DateTime
Ruby
1
star
41

norma-ruby

Ruby Loader and API for the Natural ORM Architect XML files, using the ActiveFacts API
Ruby
1
star
42

TSEvents

Touchscreen event dispatcher for Arduino LCD Screens
C++
1
star
43

webdigester

Compute MD5 and SHA256 in the browser, using file select or drag&drop
HTML
1
star
44

chattr

Type-checked attributes and arrays
Ruby
1
star
45

blogical

A micro blogging engine with no database, in Sinatra
Ruby
1
star
46

activefacts-orm

ORM format importer for the ActiveFacts fact modeling suite
Ruby
1
star
47

activefacts-api-verbalisation

Verbalisation support for the ActiveFacts API
Ruby
1
star
48

wifi_credentials

ESP32: Manage saved credentials for WiFi access points
1
star
49

activefacts-compositions

Create and represent composite schemas, schema transforms and data transforms over a fact-based model
Ruby
1
star