How to Look Up an ASN with an API
Learn how to map an IP address to its ASN, query ASN details, verify ownership with RDAP, and retrieve routing policy with practical API examples.
To look up an ASN with an API, start with the data you have: call an IP-to-ASN endpoint when you have an IPv4 or IPv6 address, or call an ASN-details endpoint when you already have an AS number. Use registry RDAP or WHOIS to verify registration and ownership claims, and use an IRR API when you need routing-policy objects such as aut-num.
Choose the right ASN lookup
| Your input | Use | Typical result |
|---|---|---|
| IP address | IP-to-ASN lookup | Announcing ASN and organization |
ASN such as AS13335 |
ASN details endpoint | Organization, prefixes, address-space summary |
| Ownership or registration claim | Registry RDAP/WHOIS | Standardized registration data |
| Routing policy | IRR aut-num query |
RPSL or XML routing-policy object |
Look up an ASN from an IP address
ipinfo.app documents this endpoint:
GET https://ip2asn.ipinfo.app/api/v1/:ip
curl https://ip2asn.ipinfo.app/api/v1/1.1.1.1
A successful response contains the input ip, an announcedBy object, and an error field. The ASN is in announcedBy.number; the announcing organization is in announcedBy.description.
{
"ip": "1.1.1.1",
"announcedBy": {
"number": 13335,
"description": "Cloudflare, Inc."
},
"error": null
}
Read the response defensively. Treat a non-null error, a missing announcedBy object, or a missing ASN number as a lookup failure rather than as an unknown organization.
Python
import ipaddress
import requests
ip = "1.1.1.1"
ipaddress.ip_address(ip) # raises ValueError for invalid IPv4/IPv6 input
url = f"https://ip2asn.ipinfo.app/api/v1/{ip}"
response = requests.get(url, timeout=15)
response.raise_for_status()
data = response.json()
if data.get("error"):
raise RuntimeError(data["error"])
announced_by = data.get("announcedBy") or {}
number = announced_by.get("number")
organization = announced_by.get("description")
if number is None:
raise LookupError(f"No ASN found for {ip}")
print({"asn": number, "organization": organization})
Node.js
const ip = '1.1.1.1';
// Validate with the URL form your application accepts before making the request.
const res = await fetch(`https://ip2asn.ipinfo.app/api/v1/${encodeURIComponent(ip)}`);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = await res.json();
if (data.error) throw new Error(data.error);
const announcedBy = data.announcedBy ?? {};
if (announcedBy.number == null) throw new Error(`No ASN found for ${ip}`);
console.log({ asn: announcedBy.number, organization: announcedBy.description });
Look up details when you already know the ASN
ipinfo.app documents an ASN-details endpoint that accepts either a bare integer or an AS-prefixed value:
GET https://asn.ipinfo.app/api/json/details/{asn}
curl https://asn.ipinfo.app/api/json/details/13335
curl https://asn.ipinfo.app/api/json/details/AS13335
The example response includes the ASN, organization name, total prefix count, IPv4 and IPv6 address-space sizes, and subnet-mask distributions. Keep the ASN normalized in your own code, but send the form accepted by the provider.
Python ASN normalization
import re
import requests
raw = "AS13335"
match = re.fullmatch(r"(?i)AS?(\\d+)", raw.strip())
if not match:
raise ValueError("ASN must look like 13335 or AS13335")
asn = match.group(1)
url = f"https://asn.ipinfo.app/api/json/details/{asn}"
r = requests.get(url, timeout=15)
r.raise_for_status()
print(r.json())
Node.js ASN normalization
const raw = 'AS13335';
const match = raw.trim().match(/^AS?(\\d+)$/i);
if (!match) throw new Error('ASN must look like 13335 or AS13335');
const asn = match[1];
const res = await fetch(`https://asn.ipinfo.app/api/json/details/${asn}`);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
console.log(await res.json());
Use an enriched ASN API for prefixes, peers, and allocation data
For richer commercial metadata, IPinfo documents an ASN API at /ASXX/json. Its schema includes the AS-prefixed number, organization name, country, allocation data, assigned prefixes, and peer ASNs. IPinfo also describes fields such as registry name, domain, ASN type, related domains, allocation date, total IP addresses, and assigned prefixes.
Use enrichment APIs when you need convenient JSON for classification, inventory, prefix lists, peers, or related domains. Do not treat an enrichment record as the authoritative registration record.
Verify ownership with RDAP or WHOIS
When your application makes an ownership, organization, or registration claim, verify it with the relevant registry’s RDAP or WHOIS service. ARIN’s Whois-RWS documentation says that, as of 2019, ARIN strongly recommends Whois/RDAP because of standardization, security support, and access to registration information from other RIRs, registrars, and organizations that support RDAP.
A practical two-stage workflow is:
- Use an IP-to-ASN or ASN enrichment API to obtain a fast, structured result.
- Check the corresponding registry RDAP/WHOIS record before treating ownership or contact details as authoritative.
Query routing policy with an IRR API
An ASN ownership lookup and a routing-policy lookup answer different questions. If you need Internet Routing Registry data, ARIN’s IRR REST guide documents:
GET /rest/irr/aut-num/ASN
The request requires an API key. You can request RPSL or XML with the Accept header. Use an IRR aut-num object when you need policy statements and routing relationships rather than a basic organization name.
Build a provider-independent lookup function
input = user supplied IP address or ASN
if input is an IP address:
call an IP-to-ASN API
read announcedBy.number and announcedBy.description
else:
normalize AS12345 and 12345
call an ASN details endpoint
validate important ownership claims with registry RDAP/WHOIS
if routing policy is needed:
query an IRR aut-num object
Keep the provider response and your normalized fields separately. Store the original input, lookup timestamp, provider, response status, ASN, organization, and any error. This makes it possible to explain changes when an address is re-announced or a provider updates its enrichment record.
Common errors and fixes
| Symptom | Likely cause | Fix |
|---|---|---|
| Invalid IP error | Malformed IPv4 or IPv6 input | Validate with a standard IP parser before building the URL. |
No announcedBy result |
The address is not announced or the provider has no record | Handle it as “no ASN found”; do not infer ownership. |
| ASN endpoint returns 404 or validation error | Input contains unexpected text such as ASN-13335 |
Normalize to digits or the provider’s documented AS-prefixed form. |
| HTTP 401 or 403 | Endpoint requires credentials or an API key | Check the provider’s authentication requirements; IRR requests require an API key. |
| HTTP 429 | Rate limit exceeded | Use bounded retries with exponential backoff, cache stable results, and respect provider limits. |
| Timeout | Network delay or provider load | Set a finite timeout, retry idempotent GET requests, and expose an unknown result instead of blocking indefinitely. |
| Conflicting organization names | Enrichment and registry data differ or changed over time | Show the source and timestamp, then use RDAP/WHOIS for registration verification. |
Performance, reliability, and cost considerations
- Cache carefully: ASN-to-organization data usually changes less often than operational IP announcements. Cache with a documented TTL and refresh when a decision depends on current routing.
- Separate hot and cold paths: Return cached enrichment quickly, then refresh asynchronously when the record is stale.
- Retry only safe requests: These lookups are GET requests, but retries still need a cap and backoff to avoid amplifying an outage or rate limit.
- Record provenance: Keep provider, timestamp, HTTP status, and raw response fields needed for auditability.
- Plan for IPv6: Do not split addresses on colons or assume dotted-decimal input.
- Control cost: No single API is authoritative for every purpose. Use the least expensive endpoint that answers the question, and reserve paid enrichment or registry queries for fields you actually need.
Or skip the browser setup
If you need a screenshot of an ASN lookup result for documentation, monitoring, or an internal report, ScreenshotNeo returns an image or PDF from one GET request. It removes cookie banners, newsletter popups, and chat widgets before capture. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and response headers identify the page verdict and billing result. Its MCP server provides take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients.
See the ScreenshotNeo API documentation. The same request can be made with cURL:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
Python
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
Node.js
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
ScreenshotNeo includes 1,000 screenshots per month free with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account.
FAQ
Can an ASN API identify the exact network operator?
It can return the announcing ASN and an organization label. Verify registration ownership with RDAP or WHOIS when accuracy matters.
Should I send AS13335 or 13335?
Use the format documented by your provider. The ipinfo.app details endpoint accepts both forms; normalizing internally avoids accidental format errors.
Does an ASN lookup show routing policy?
Basic ASN and IP-to-ASN endpoints do not replace routing-policy data. Query an IRR aut-num object when you need RPSL or XML policy information.
Why can two APIs return different organizations?
They may use different enrichment sources, update schedules, or naming conventions. Compare timestamps and verify important claims against registry data.


