Back to snippets

maxminddb_geoip_database_open_and_ip_lookup.py

python

This quickstart demonstrates how to open a MaxMind DB file and perform a recor

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 this object for multiple 
4# lookups as it is 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    record = reader.get('1.1.1.1')
8    
9    print(record)
maxminddb_geoip_database_open_and_ip_lookup.py - Raysurfer Public Snippets