Loading
Loading
Explore the complete API reference with detailed request parameters, response fields, error codes, and code examples: visit API Reference.
Pass the AS number in asn. The response is the network's whole profile: who holds the AS number, every prefix it announces, its peers, upstreams and downstreams, the contacts in its registry record, and the registry text itself, parsed and raw.
whoisHost names the registry that answered, one of ARIN, RIPE NCC, APNIC, LACNIC or AFRINIC. The request goes to the right one on its own.
The lists and the registry text are cut short here. A real response returns every entry.
asn takes the number with or without the AS prefix, in any case: AS1234, as1234 and 1234 return the same record. It must be a whole number above zero. 32-bit AS numbers work like any other.
Set format=xml for the same data as XML. JSON is the default.
The registry text is cut short here. This network announces three prefixes, has two upstreams and no downstreams.
routeObjects lists every prefix the network announces, IPv4 and IPv6 together. Each entry has the prefix in CIDR notation, the AS that originates it, the name behind it and the number of addresses it holds. numOfIPv4Routes and numOfIPv6Routes give the totals for each version before you loop. They arrive as strings.
Tell the versions apart by the colon in the prefix. An IPv6 prefix can hold more addresses than a JavaScript number keeps exactly, as the last entry below does, so read numberOfIps as a string or a big integer when you add them up.
A network can announce nothing. Many ASNs are registered but never appear in the global routing table, and their lookup returns the registration with an empty routeObjects list.
Only the first entries are shown. To block or allow a network, use every prefix in the list.
The response holds three lists of neighbors, each entry with the AS number, the name and the country. peers is every network this one connects to over BGP. upstreams are the ones it pays for internet access, its transit providers, and downstreams are the ones that pay it for access.
Upstreams and downstreams are also listed under peers, so peers is the full list and the other two are smaller groups inside it. A network can appear in both upstreams and downstreams.
To list the neighbors that are neither upstream nor downstream, take the upstreams and downstreams out of peers:
contacts gathers the email addresses from the registry record: abuseContacts for reporting abuse and emailContacts for the technical and administrative contacts. The full contact records, with handles, names and phone numbers, are under parsedWhoisResponse.
When a network is hijacking a prefix or sending abuse, the abuse contact tells you who to report it to.
Not every network publishes an abuse contact, and what a record holds follows its registry. This record has none, so both lists are empty, and the raw registry text says so:
legacyRoutes is a list of prefixes tied to the network that are no longer among its current routes. They are plain CIDR strings. Current prefixes are in routeObjects.
The list is empty for many networks. Use it to see where a network used to be, and use routeObjects for what it announces now.
Only the first entries of each list are shown.
The ASN Lookup API takes an AS number, so an investigation that starts from an IP address takes two calls. Send the IP to the IP Geolocation API, which returns its ASN in asn.as_number. Ask for only that field with fields to keep the response small. For many addresses, use the Bulk IP Geolocation Lookup API.
Then pass that number to this API. One lookup covers every IP in the network, so look each network up once, not each address.
The two calls together:
For the allocation record of a single address block, use the IP WHOIS Lookup API.
Each lookup is a snapshot. Save the prefixes and the upstreams of the networks you track, look them up again on a schedule and compare. A new prefix can be a planned expansion or an announcement nobody on your side expected, and a new upstream is a new transit path, so check each against what you expect.
The script below looks up each network in a list, compares it with the last run and prints what was added or removed. Run it from a scheduler such as cron.
To check who announces a prefix, look up its holder with the IP WHOIS Lookup API and compare it with the organization behind the ASN announcing it. A mismatch is a lead to check, not a verdict: a provider announcing a customer's prefix looks the same.
An asn that is not a number, is zero or is not a whole number returns 400. A missing asn also returns 400, and an unsupported format returns 406.
An AS number the registries have no record of returns 404. Reserved numbers, such as the ones set aside for documentation, are not in the registries either. Errors are not charged, and any charge already taken for them is refunded.
An AS number with no record looks like this:
import requestsurl = "https://api.apifreaks.com/v1.0/asn/whois/live?asn=AS13335"payload = {}headers = {'X-apiKey': 'YOUR_API_KEY'}response = requests.request("GET", url, headers=headers, data=payload)print(response.text)