Description

Chicken bindings for the GeoIP C API library, implementing most of the useful API procedures for accessing the freely available GeoIP Standard Country database.

Author

Arto Bendiken

Version

Usage

(require-extension geoip)

Download

geoip.egg

Documentation

To build this extension, you will need a current version of the GeoIP C API library installed.

Database operations

Note that it is not necessary to explicitly use the following two procedures for accessing the GeoIP Standard Country database, as all the lookup procedures will use that database by default if no DB argument is given.

procedure: (geoip:open [FILENAME] [FLAGS])

Opens a GeoIP database with the specified FILENAME and FLAGS, and returns it as a geoip:database object. With no arguments given, will attempt to open the default GeoIP.dat that ships with the GeoIP library. To enable caching, pass one of the following constants in FLAGS:

GEOIP-STANDARD Read database from file system. This is the default and uses the least memory.
GEOIP-MEMORY-CACHE Load database into memory. Faster performance but uses more memory.
GEOIP-CHECK-CACHE Check for updated database. If the database has been updated, reload the file handle and/or memory cache.
GEOIP-INDEX-CACHE
Just cache the most frequently accessed index portion of the database, resulting in faster lookups than with GEOIP-STANDARD, but less memory usage than GEOIP-MEMORY-CACHE. Useful for larger databases such as GeoIP Organization and GeoIP City.
procedure: (geoip:open-type TYPE FLAGS)

Opens a GeoIP database of the specified TYPE from the standard installation location (usually /usr/local/share/GeoIP/. The FLAGS are the same as for (geoip:open), and TYPE can be one of the following constants:

GEOIP-COUNTRY-EDITION
GEOIP-REGION-EDITION-REV0
GEOIP-CITY-EDITION-REV0
GEOIP-ORG-EDITION
GEOIP-ISP-EDITION
GEOIP-CITY-EDITION-REV1
GEOIP-REGION-EDITION-REV1
GEOIP-PROXY-EDITION
GEOIP-ASNUM-EDITION
GEOIP-NETSPEED-EDITION

Database information

procedure: (geoip:database-available? TYPE)

Determines whether a GeoIP database of the class TYPE has been installed.

procedure: (geoip:database-edition [DB])

Returns a constant indicating the type of the specified GeoIP database. When called without an argument, returns the type of the default database.

procedure: (geoip:database-info [DB])

Returns a string containing information about the specified GeoIP database, including the type and release date. When called without an argument, returns information on the default database.

Country code lookup (2-letter)

procedure: (geoip:country-code-by-addr ADDR [DB])

Looks up a 2-letter ISO 3166-1 country code based on the specified IP address.

procedure: (geoip:country-code-by-name NAME [DB])

Looks up a 2-letter ISO 3166-1 country code based on the specified hostname.

Country code lookup (3-letter)

procedure: (geoip:country-code3-by-addr ADDR [DB])

Looks up a 3-letter ISO 3166-1 country code based on the specified IP address.

procedure: (geoip:country-code3-by-name NAME [DB])

Looks up a 3-letter ISO 3166-1 country code based on the specified hostname.

Country name lookup

procedure: (geoip:country-name-by-addr ADDR [DB])

Looks up a country name based on the specified IP address.

procedure: (geoip:country-name-by-name NAME [DB])

Looks up a country name based on the specified hostname.

Examples

(use geoip)

(geoip:database-available? GEOIP-COUNTRY-EDITION)  ; => #t
(geoip:database-available? GEOIP-ISP-EDITION)      ; => #f

(geoip:database-edition)  ; => #\x1 (i.e. GEOIP-COUNTRY-EDITION)
(geoip:database-info)     ; => "GEO-106FREE 20050901 Build 1 Copyright (c) 2005 MaxMind LLC All Rights Reserved"

(geoip:country-code-by-name "www.call-with-current-continuation.org")  ; => "DE"
(geoip:country-code-by-addr "194.97.107.133")                          ; => "DE"
(geoip:country-code3-by-name "www.google.com")                         ; => "USA"
(geoip:country-name-by-name "www.bbc.co.uk")                           ; => "United Kingdom"

License

Copyright (c) 2006 Arto Bendiken. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.

This product includes GeoLite data created by MaxMind.