import pygeoip import requests import smtplib import socket ip = requests.get('https://api.ipify.org').text def get_location(ip): gip = pygeoip.GeoIP('GeoLiteCity.dat') res = gip.record_by_addr(ip) print(f'IP: {ip}') print(f"Continent: {res['continent']}") print(f"Country: {res['country_name']}") print(f"Location: {res['city']}, {res['region_code']}") print(f"Postal Code: {res['postal_code']}") print(f"Area Code: {res['area_code']}") print(f"Time Zone: {res['time_zone']}") print(f"Estimated Latitude: {res['latitude']}") print(f"Estimated Longitude: {res['longitude']}") get_location(ip)