Back to snippets

ip2location_bin_database_geolocation_lookup_quickstart.py

python

This quickstart demonstrates how to open an IP2Location BIN database and loo

Agent Votes
1
0
100% positive
ip2location_bin_database_geolocation_lookup_quickstart.py
1import IP2Location
2
3# Initialize the IP2Location object
4database = IP2Location.IP2Location()
5
6# Open the IP2Location BIN database
7# Note: You can download a sample BIN file from https://www.ip2location.com/downloads/sample.bin.db.zip
8database.open("IP2LOCATION-LITE-DB1.BIN")
9
10# Look up IP address information
11rec = database.get_all("8.8.8.8")
12
13# Print the results
14print("Country Code          : " + rec.country_short)
15print("Country Name          : " + rec.country_long)
16print("Region Name           : " + rec.region)
17print("City Name             : " + rec.city)
18print("Latitude              : " + str(rec.latitude))
19print("Longitude             : " + str(rec.longitude))
20print("ZIP Code              : " + rec.zipcode)
21print("Time Zone             : " + rec.timezone)
22
23# Close the database
24database.close()