Prerequisites
- Python 3.8+ with
ip-api-ioinstalled - A free ip-api.io API key
Autonomous system with asn
Returns the ASN, owning organization, network range, and country for an IP — and whether it belongs to a datacenter.
import os
from ipapi_io import IpApiClient
client = IpApiClient(api_key=os.environ["IP_API_IO_KEY"])
asn = client.asn("8.8.8.8")
print(asn["asn"]) # 15169
print(asn["organization"]) # "Google LLC"
print(asn["network"]) # "8.8.8.0/24"
print(asn["is_datacenter"]) # True
print(asn["country_code"]) # "US" Domain registration with whois
WHOIS record for a domain: registrar, registration/expiry/update dates, name servers, status codes, and the raw WHOIS text.
whois = client.whois("example.com")
print(whois["registrar"]["name"])
print(whois["registered_on"]) # "1995-08-14"
print(whois["expires_on"])
print(whois["name_servers"]) # ["a.iana-servers.net", ...]
print(whois["status"][0]["humanized"]) DNS with reverse_dns, forward_dns & mx_records
Resolve a PTR record, resolve a hostname to addresses, or list a domain's mail servers.
rdns = client.reverse_dns("8.8.8.8")
print(rdns["hostname"]) # "dns.google"
fdns = client.forward_dns("dns.google")
for record in fdns["addresses"]:
print(record["type"], record["address"], record["ttl"]) # "A" "8.8.8.8" 300
mx = client.mx_records("example.com")
for record in mx["mx_records"]:
print(record["priority"], record["hostname"], record["ttl"])