Python
Python Examples
You’ll need the requests library. If you don’t have it, run pip install requests. You probably already have it though.
All Seven Endpoints
Get Your Own IP
import requests
response = requests.get("https://whatismyip.technology/api/me")
data = response.json()
print(f"Your IP: {data['ip']}")
Full IP Lookup
response = requests.get("https://whatismyip.technology/api/8.8.8.8")
data = response.json()
print(f"City: {data['city']}")
print(f"Country: {data['country']}")
print(f"ISP: {data['asn']['name']}")
Geolocation Only
response = requests.get("https://whatismyip.technology/api/8.8.8.8/geo")
geo = response.json()
print(f"Location: {geo['city']}, {geo['region']}, {geo['country']}")
print(f"Coordinates: {geo['latitude']}, {geo['longitude']}")
ASN and Network Info
response = requests.get("https://whatismyip.technology/api/8.8.8.8/asn")
asn = response.json()
print(f"ASN: {asn['number']}")
print(f"Org: {asn['org']}")
Privacy and Threat Detection
response = requests.get("https://whatismyip.technology/api/8.8.8.8/privacy")
privacy = response.json()
print(f"VPN: {privacy['is_vpn']}")
print(f"Proxy: {privacy['is_proxy']}")
print(f"Tor: {privacy['is_tor']}")
Company and Abuse Info
response = requests.get("https://whatismyip.technology/api/8.8.8.8/company")
company = response.json()
print(f"Name: {company['name']}")
print(f"Type: {company['type']}")
Bulk Lookup
response = requests.post(
"https://whatismyip.technology/api/bulk",
json={"ips": ["8.8.8.8", "1.1.1.1", "208.67.222.222"]}
)
results = response.json()
for result in results:
print(f"{result['ip']} -> {result['country']}")
Error Handling
Always check for errors. The internet is a rough place.
import requests
def lookup_ip(ip):
try:
response = requests.get(
f"https://whatismyip.technology/api/{ip}",
timeout=10
)
response.raise_for_status()
return response.json()
except requests.exceptions.Timeout:
print("Request timed out. Try again.")
return None
except requests.exceptions.HTTPError as e:
print(f"HTTP error: {e.response.status_code}")
return None
except requests.exceptions.RequestException as e:
print(f"Something went wrong: {e}")
return None
data = lookup_ip("8.8.8.8")
if data:
print(f"{data['ip']} is in {data['city']}, {data['country']}")
Async Version with aiohttp
For when you need to look up a bunch of IPs without waiting for each one to finish.
import asyncio
import aiohttp
async def lookup_ip(session, ip):
async with session.get(f"https://whatismyip.technology/api/{ip}") as response:
return await response.json()
async def main():
ips = ["8.8.8.8", "1.1.1.1", "208.67.222.222", "9.9.9.9"]
async with aiohttp.ClientSession() as session:
tasks = [lookup_ip(session, ip) for ip in ips]
results = await asyncio.gather(*tasks)
for result in results:
print(f"{result['ip']} -> {result['city']}, {result['country']}")
asyncio.run(main())
Install aiohttp first: pip install aiohttp
Complete Script
Here’s a script you can actually save and run. It takes an IP as an argument, looks it up, and prints a nice summary.
#!/usr/bin/env python3
"""Look up any IP address using the WhatIsMyIP API."""
import sys
import requests
API_BASE = "https://whatismyip.technology/api/me"
def main():
if len(sys.argv) < 2:
url = API_BASE
print("No IP provided, looking up your own...")
else:
ip = sys.argv[1]
url = f"{API_BASE}/{ip}"
try:
response = requests.get(url, timeout=10)
response.raise_for_status()
data = response.json()
except Exception as e:
print(f"Failed: {e}")
sys.exit(1)
print(f"IP: {data['ip']}")
print(f"Location: {data.get('city', '?')}, {data.get('region', '?')}, {data.get('country', '?')}")
print(f"ISP: {data.get('asn', {}).get('name', 'Unknown')}")
privacy = data.get("privacy", {})
if privacy.get("is_vpn"):
print("Note: This IP is behind a VPN")
if privacy.get("is_tor"):
print("Note: This IP is a Tor exit node")
if __name__ == "__main__":
main()
Save it as iplookup.py and run it:
python iplookup.py 8.8.8.8
python iplookup.py # looks up your own IP