• Stars
    star
    153
  • Rank 242,437 (Top 5 %)
  • Language
    C
  • Created over 15 years ago
  • Updated almost 10 years ago

Reviews

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

Repository Details

Ruby C binding to Maxmind GeoIP Library

Ruby GeoIP Bindings

What?

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.

Usage

require 'geoip'
db = GeoIP::City.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 arguments to database initializer.

  1. The first argument is the filename of the GeoIPCity.dat file

  2. The second argument (optional) is to specify how GeoIP should keep the database in memory. There are three possibilities

    • :filesystem -- Read database from filesystem, uses least memory.

    • :index -- The most frequently accessed index portion of the database, resulting in faster lookups than :filesystem, but less memory usage than :memory.

    • :memory -- (Default.) Load database into memory, faster performance but uses more memory.

  3. 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

GeoIP::City.new(dbfile, :filesystem, true)

Usage for Organization Search

require 'geoip'
db = GeoIP::Organization.new('/opt/GeoIP/share/GeoIP/GeoIPOrg.dat')
db.look_up('24.24.24.24')
# => {:name=>"Road Runner"}

The name is the only data available for Organizations.

Install

Some variation of the following should work.

  1. Install the GeoCity C library. You can get it from MaxMind. For example, I like to install mine in /opt/GeoIP, so I do this:

    tar -zxvf GeoIP-1.4.3.tar.gz cd GeoIP-1.4.3 ./configure --prefix=/opt/GeoIP make && sudo make install

On Mac OS X, you can install using [homebrew](http://github.com/mxcl/homebrew):

    brew install geoip

Linux platforms utilizing Apt have several packages available:

    geoip-bin
    geoip-database
    libgeoip-dev
  1. Now install the geoip gem

    gem install geoip-c -- --with-geoip-dir=/opt/GeoIP

Alternatively, if you installed libgeoip using homebrew:

    gem install geoip-c
  1. Download the GeoLite City database file in binary format at http://www.maxmind.com/app/geolitecity Maybe this direct link will work. I put this file in

    /opt/GeoIP/share/GeoIP/GeoLiteCity.dat

If you installed libgeoip using homebrew then put it in:

    /usr/local/share/GeoIP/GeoLiteCity.dat

 If you are a paying customer, you will download the files required below:

 [MaxMind Customer Downloads](http://www.maxmind.com/app/download_files)

 You will want to get the City Rev1 data file and Organization files at minimum.
  1. Use it!

    See above for usage details.

Hints

  1. Might need to set

    export ARCHFLAGS="-arch i386"

to be able to compile the gem.

Example:

    env ARCHFLAGS="-arch i386" gem install geoip-c -- --with-geoip-dir=/opt/GeoIP
  1. You might find this shell script helpful to install the C library.

Links

This iteration of the library is based on the hard work of Ryah Dahl ([email protected]). You can find the original RDocs and Git Repo below:

rdocs git repo

Thanks

Special appreciation and thanks belongs to Ry Dahl for his initial work on this library.

Many thanks to our contributors:

  • Charles Brian Quinn (seebq)
  • Michael Sheakoski
  • Silvio Quadri
  • Leonardo Almeida (leogalmeida)

License

Copyright (C) 2007--2009 Ryah Dahl ([email protected]), Matt Todd ([email protected])

This program is free software. It comes without any warranty, to the extent permitted by applicable law. You can redistribute it and/or modify it under the terms of the Do What The Fuck You Want To Public License, Version 2, as published by Sam Hocevar. See http://sam.zoy.org/wtfpl/COPYING for more details.

More Repositories

1

halcyon

JSON Web App Framework [NOT UNDER ACTIVE DEVELOPMENT]
Ruby
62
star
2

pingdom-client

Pingdom Ruby Client (Unofficial)
Ruby
30
star
3

ruby-c

Ruby Extensions in C Presentation Materials for AtlRUG (2009-07-08)
C
19
star
4

ape

NOTE: abandoned experiment -- Asynchronous PErsistence of Ruby Objects
Ruby
17
star
5

deliver_later

A 2-phase database-driven ActionMailer delivery method
Ruby
16
star
6

auto-awesome

A Turntable.fm Bookmarklet for Automatic Awesome
Perl
12
star
7

scimtool

Go
11
star
8

halcyon-clients

A collection of non-Ruby clients for Halcyon applications.
Java
11
star
9

aurora

Simple Authentication System and User Management
Ruby
10
star
10

fuck

A fuckin' framework
Ruby
9
star
11

aceldama

Merb and Halcyon powered Javascript-style embedded site components server
JavaScript
7
star
12

decor

Define multiple representations of an object
Ruby
7
star
13

peaty

PivotalTracker Ruby API Client
Ruby
7
star
14

slapp

The Slapp Merb/Rspec tutorial app
Ruby
6
star
15

empty-ruby-project

Empty Ruby project with bare essentials.
Ruby
5
star
16

docufuckr

Fucks your docs in the ass!
Ruby
5
star
17

faraday-auth-hmac

Ruby
5
star
18

power

A command line option parser.
4
star
19

slits

A community site for sharing Merb Slices
Ruby
4
star
20

empty-merb-app-with-authentication

4
star
21

empty-erlang-project

Empty Erlang project with the bare essentials
Erlang
4
star
22

conley

A meshable web service Merb app
Ruby
4
star
23

xml_to_json

Transform XML To JSON
Ruby
4
star
24

freckle-client

Ruby client for the Let'sFreckle API
Ruby
4
star
25

mtodd.github.com

JavaScript
4
star
26

tab

Keeps track of inter-office tabs
Ruby
4
star
27

cadence

Helper library to provide callbacks for various intervals such as every n items.
Ruby
4
star
28

crenshaw-compiler-ruby

Following along with http://compilers.iecc.com/crenshaw/
Ruby
3
star
29

merb_proxy_logger

Injects a proxy allowing the use of custom logging libraries and settings.
3
star
30

base-authenticated-merb-app

Fuck?
3
star
31

redis-info

Scout Plugin to monitor basic Redis stats
Ruby
3
star
32

dotfiles

Y'know, .dotfiles
3
star
33

activerecord-table_version

Set table version for ActiveRecord models
Ruby
3
star
34

snoop-logg

A proxy logger for capturing data flow between two clients and/or services for recreational or educational inspection.
Ruby
3
star
35

team-sync

Replicate members list from one team to another
Ruby
3
star
36

ramble

Helping to solve the shortage of Merb-based blogging sites
Ruby
3
star
37

canvas

A PHP5 Web Application Development Framework; NOT UNDER ACTIVE DEVELOPMENT
PHP
3
star
38

extract

Exercise Metric Tracking and Intelligence
JavaScript
3
star
39

hugo-nogo

Why can't I get Hugo to work?
HTML
2
star
40

merbday

MerbDay Tutorial Resources
Ruby
2
star
41

gh-app-manifest-flow-demo

Go
2
star
42

test-install-trigger-0

2
star
43

test-install-trigger-1

2
star
44

show-password

JavaScript
2
star
45

idiolog

Merb-based Blog
2
star
46

house2

Second iteration of running through the House
2
star
47

test-install-trigger-10

2
star
48

ghjwt

Simple CLI tool for quickly generating GitHub Apps authn/authz JWTs
Go
2
star
49

house

A Warehouse
Ruby
2
star
50

ldapwatch

Go
2
star
51

test-install-trigger-6

2
star
52

test-install-trigger-9

2
star
53

jps

JSON Presence Service
2
star
54

income_planner

Tracks income and expenditures, graphing a timeline of available funds
Ruby
2
star
55

ranger

reports to a central location
Ruby
2
star
56

smq

Simple Message Queue, a Ruby Message Queue Broker/Client
Ruby
2
star
57

test-install-trigger-8

2
star
58

freelancing-god.github.com

2
star
59

nth_tweet

Ruby
1
star
60

test-install-trigger-2

1
star
61

locaterc

locate the closest filename, starting in pwd and working to root
1
star
62

test-install-trigger-3

1
star
63

mtodd

My homepage
1
star
64

queue_length

A Scout Plugin for monitoring (RabbitMQ) Queue Length
Ruby
1
star
65

sampler

Ruby
1
star
66

test-install-trigger-5

1
star
67

with_reverse_lookup

Ruby
1
star
68

test-install-trigger-4

1
star
69

rss_stream

1
star
70

midi2stdout

Dump MIDI messages to STDOUT
Go
1
star