# &adminguide;

## Overview

This module allows real-time queries against the Max Mind GeoIP database to be performed from the config script. It uses the old version of API, still very common on OS distributions. For using the new version of GeoIP API, see geoip2 module.

The Max Mind GeoIP database is a map of IP network address assignments to geographical locales that can be useful -- though approximate -- in identifying the physical location with which an IP host address is associated on a relatively granular level.

This database itself can be obtained on a free or commercial basis from http://www.maxmind.com/app/ip-location. The library that interfaces with the Max Mind API, as well as scripts to automate downloading of the on-disk version of the open-source database is also packaged by the Debian Linux distribution and its derivatives as libgeoip, and probably by other distributions as well.

Debian Linux squeeze includes already a database as dependency, but as this contain the wrong data, it will not work correctly with the module. More accurate, the module expect the GeoIP City Edition, and will not work with the GeoIP Country Edition. In newer Debian Linux releases the package geoip-database-contrib should contain the necessary database. You can download the Lite edition of the DB from http://www.maxmind.com/app/geolitecity.

This module exports a new class of pseudo-variables - $gip(pvc=>key) - to enable access to the results of a query to the database.

Many queries can be done and store results in different containers to be able to use in parallel. Database is loaded at startup in cache.

## Dependencies

### &kamailio; Modules

The following modules must be loaded before this module:

- none.

### External Libraries or Applications

The following libraries or applications must be installed before running &kamailio; with this module loaded:

- libgeoip - the GeoIP library.

## Parameters

### `path` (string)

Path to the GeoIP database file.

Default value is null.

#### Set `path` parameter

    ...
    modparam("geoip", "path", "/usr/local/share/GeoLiteCity.dat")
    ...

## Functions

### `geoip_match(ipaddr, pvc)`

Match ipaddr against the GeoIP database and set the pvc container. The function has to be called before accessing a key via: $gip(pvc=>key).

#### `geoip_match` usage

    ...
    if(geoip_match("$si", "src"))
        xlog("SIP message from: $gip(src=>cc)\n");
    ...

## Exported pseudo-variables

- $gip(pvc=>key) - pvc is an identifier for this query result; it is designated by the second parameter of geoip_match(). The key can be one of the following:

  - cc - country code

  - tz - time zone

  - zip - postal code

  - lat - latitude

  - lon - longitude

  - dma - dma code

  - ips - ip start

  - ipe - ip end

  - city - city

  - area - area code

  - regc - region

  - regn - region name

  - metro - metro code

  - contc - continent code

Exported pseudo-variables are documented at &kamwikilink;.