Python SDK · Feature

ASN & DNS Lookups in Python

Resolve the network and DNS layer behind an IP or domain: which autonomous system owns an address, who registered a domain, what a host's PTR record is, and which mail servers a domain uses — all from the same client.

Trusted by thousands of businesses
Fast JSON API responses
Real-time validation
Simple integration, SDKs & examples
What it does

Network ownership and DNS in one client

Behind every IP and domain is a network and DNS layer that tells you who owns the address space, when a domain was registered, and how its mail and hostnames resolve. ip-api.io exposes ASN, WHOIS, reverse/forward DNS, and MX lookups through the same client, so you can enrich logs, verify ownership, and feed fraud rules without juggling separate DNS libraries.

Prerequisites

1

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"
2

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"])
3

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"])
Reference

Response reference

MethodReturnsKey fields
asn(ip)AsnLookupip, asn, organization, network, is_datacenter, country, country_code
whois(domain)Whoisdomain, registrar, registered_on, expires_on, updated_on, name_servers, status, raw
reverse_dns(ip)ReverseDnsip, hostname, ptr_record, ttl
forward_dns(hostname)ForwardDnshostname, addresses (each type, address, ttl)
mx_records(domain)MxLookupdomain, mx_records (each priority, hostname, ttl)
FAQ

Frequently asked questions

How do I find the ASN and owner of an IP in Python?

Call client.asn(ip). It returns the ASN number, owning organization, network range, country, and whether the IP belongs to a datacenter.

How do I do a WHOIS lookup in Python?

Use client.whois(domain). It returns the registrar, registration/expiry/update dates, name servers, status codes, and the raw WHOIS text for a domain.

Can I do reverse and forward DNS lookups?

Yes. client.reverse_dns(ip) returns the PTR hostname for an IP, and client.forward_dns(hostname) resolves a hostname to its A/AAAA addresses. client.mx_records(domain) returns a domain's mail servers.

What's the difference between mx_records here and email validation?

mx_records(domain) returns the raw MX records (priority, hostname, ttl) for DNS inspection. The email validation methods use MX presence as one input to a deliverability verdict for a specific address.

Start building with the ip-api.io Python SDK

Install ip-api-io, drop in your free API key, and ship in minutes — one zero-dependency client for geolocation, fraud detection, and email validation.

Need support?

Explore how IP-API.io can enhance your security, provide robust bot protection, and improve IP geolocation accuracy for your applications.

Contact Support

Found a bug in the SDK?

The ip-api-io package is open source. Open an issue or pull request on GitHub and we'll take a look.

Open on GitHub