Did you know ... Search Documentation:
Pack geoip -- prolog/geoip.pl
PublicShow source

This library provides a minimal interface to the public GeoIP library from MAXMIND

It has been tested with the Ubuntu package libgeoip-dev with the databases from the package geoip-database-contrib, which are by default installed in =/usr/share/GeoIP=. A simple usage is:

?- tcp_host_to_address('www.swi-prolog.org', IP),
   geoip_lookup(IP, R).
R = geoip{city:'Amsterdam',
To be done
- Implement more of the GeoIP library API.
 geoip_open(+Name, -Handle) is det
True when Handle is a handle to the GeoIP database Name. The database file is searched for using the pattern geoip(Name.dat). Subsequent calls to this predicate return the handle to the already opened database.
 geoip_open(+File, +Mode, -Handle) is det
Open the GeoIP database file File in Mode and return a handle for it. File may use alias patterns. The default configuration provides the alias geoip, pointing to ='/usr/share/GeoIP=. Mode is one of standard, memory_cache, check_cache, index_cache or mmap_cache. Consult the library documentation for the meaning of these constants. For example:
?- geoip_open(geoip('GeoIPCity.dat'), standard, H).
H = <geoip>(0x1f3ae30).

Database handles are subject to (atom) garbage collection. If a database handle is garbage collected, the underlying database is closed.

 geoip_close is det
 geoip_close(?NameOrHandle) is det
Close all databases or those matching NameOrHandle.
 geoip_lookup(+From, -Result) is semidet
 geoip_lookup(+Handle, +From, -Result) is semidet
Find a record from the GeoIP database. The predicate geoip_lookup/2 uses geoip_open('GeoIPCity', Handle) to get a handle to the GeoIP city database. Result is a dict, containing a subset of the following keys: country_code, country_code3, country_name, region, city, postal_code, continent_code, latitude, longitude, netmask or area_code. This predicate uses GeoIP_record_by_ipnum() from the GeoIP library.
From- is either a term ip(A,B,C,D) or a dotted string or atom containing an ip4 address or hostname. If From is a hostname, tcp_host_to_address/2 is used to lookup the IP address.

Undocumented predicates

The following predicates are exported, but not or incorrectly documented.

 geoip_lookup(Arg1, Arg2, Arg3)