Boilerplate setup for GeoIP. GeoIP allows us to look up the country code associated with an IP address. This is a “pure” python version which interacts with the Maxmind GeoIP API (version 1). It requires, in Debian, the libgeoip-dev and geoip-database packages.
getCountryCode
(ip)[source]¶Return the two-letter country code of a given IP address.
Parameters: | ip (ipaddr.IPAddress ) – An IPv4 OR IPv6 address. |
---|---|
Return type: | None or str |
Returns: | If the GeoIP databases are loaded, and the ip lookup is
successful, then this returns a two-letter country code. Otherwise,
this returns None . |