Usage
The mmdb
file format, short for MaxMind
Data Base, used by IPNetDB
is compatible with all existing libraries that can read mmdb
files. Any
language or server that is uses libmaxminddb
can read
IPNetDB databases. Usage examples:
$ pip install maxminddb
$ python
Python 3.9.5
Type "help", "copyright", "credits" or "license" for more information.
>>> import maxminddb, pprint
>>> reader = maxminddb.open_database('ipnetdb_prefix_latest.mmdb')
>>> data = reader.get('208.115.128.62')
>>> pprint.pprint(data)
{'allocation': '208.115.128.0/20',
'allocation_cc': 'US',
'allocation_registry': 'arin',
'allocation_status': 'allocated',
'as': 264668,
'as_cc': 'EC',
'as_entity': 'NEGOCIOS Y TELEFONIA NEDETEL S.A.',
'as_name': '',
'as_private': False,
'as_registry': 'arin',
'ix': {'exchange': 'Equinix Bogota',
'organisation': 'Equinix, Inc.',
'name': 'Amazon IVS / Twitch',
'speed': 10000},
'prefix': '208.115.128.0/24',
'prefix_asset': [],
'prefix_assignment': 'assignment',
'prefix_bogon': False,
'prefix_cc': 'EC',
'prefix_entity': 'NSI Hosting',
'prefix_name': 'EQUINIX-IX-BG',
'prefix_origins': [264668],
'prefix_registry': 'arin',
'rpki_status': 'unsigned'}
Some maxxminddb
libraries, like the Python bindings, require
the query to be in the format of an IP address. You can convert your
ASN from a 32bit integer into a dotted quad format first if this is required as in
the example below.
$ pip install maxminddb
$ python
Python 3.9.5
Type "help", "copyright", "credits" or "license" for more information.
>>> import maxminddb, pprint, ipaddress
>>> reader = maxminddb.open_database('ipnetdb_asn_latest.mmdb')
>>> asn_in_ip_format = ipaddress.ip_address(58682)
>>> data = reader.get(asn_in_ip_format)
>>> pprint.pprint(data)
{'as': 58682,
'cc': 'BD',
'entity': 'Level3 Carrier Ltd.',
'in_use': True,
'ipv4_prefixes': ['103.15.40.0/24',
'103.15.41.0/24',
'103.15.42.0/24',
'103.15.43.0/24',
'103.124.226.0/24',
'103.124.225.0/24',
'103.124.227.0/24',
'43.228.208.0/24',
'43.228.209.0/24'],
'ipv6_prefixes': ['2404:c900:4::/48',
'2404:c900:5::/48',
'2404:c900:a::/48',
'2404:c900:1::/48',
'2404:c900:3::/48',
'2404:c900:6::/48',
'2404:c900:8::/48',
'2404:c900:9::/48',
'2404:c900:b::/48'],
'name': 'LEVEL3-BD',
'peers': [6939,
137409,
2914,
1828,
199524,
58952,
9498,
58682,
174,
6453,
18106,
133210,
14907],
'private': False,
'registry': 'apnic',
'status': 'allocated',
'ix': [{'exchange': 'Equinix Singapore',
'ipv4': '27.111.228.13',
'ipv6': '2001:de8:4::5:8682:1',
'organisation': 'Eqinix Inc',
'speed': 100000},
{'exchange': 'SGIX',
'ipv4': '103.16.102.228',
'ipv6': '2001:de8:12:100::228',
'organisation': 'Singapore Internet Exchange Limited',
'speed': 100000},
{'exchange': 'DE-CIX Mumbai',
'ipv4': '103.27.171.184',
'ipv6': '2401:7500:fff6::12d',
'organisation': 'DE-CIX Interwire Internet Services Pvt Ltd',
'speed': 100000}]
Note that IPNetDB is not a IP to
geolocation tool. The country codes returned are from the IANA allocation information
and are not accurate for use in geolocation. Country codes are accurate to determine
the country that an IP address or ASN was originally allocated to, but not a specific
location.
The format stored in IPNetDB databases is different
to that stored by other mmdb
databases so remember you will need to use
the libmaxminddb
based libraries directly and not any
GeoIP libraries.
The above table is not exhaustive, native libmaxminddb
implementations exist for many additional languages.
The mmdb
format as well as all of the maxmind
libraries are developed by MaxMind. MaxMind and GeoIP
are registered trademarks of MaxMind, Inc. IPNetDB does not use any existing MaxMind data and
the databases are generated using the open source MaxMind database creation libraries.