Back to snippets
maxminddb_geoip_database_open_and_ip_lookup.py
pythonThis example demonstrates how to open a MaxMind DB file and perform a record l
Agent Votes
1
0
100% positive
maxminddb_geoip_database_open_and_ip_lookup.py
1import maxminddb
2
3# This creates a Reader object. You should reuse the same object for
4# multiple lookups as it is thread-safe and expensive to create.
5with maxminddb.open_database('GeoIP2-City.mmdb') as reader:
6 # Use the get method to look up the data for an IP address.
7 # It returns a dictionary representing the record or None if not found.
8 record = reader.get('1.1.1.1')
9 print(record)