Skip to main content

aslookup

Python client for IP to ASN lookup services

aslookup is a client utility for two of the public IP/AS query services operated by the following organizations:

The client implements both a simple Python module (aslookup) as well as a CLI utility (as-lookup). The lookups are done using DNS with asynchronous processing for improved performance when handling multiple IP addresses.

Both IPv4 and IPv6 addresses are supported. The client also maintains a listing of IP networks which are unroutable internet addresses, typically in special use RFC ranges. In this way it can both filter out addresses from queries which are a waste of time, as well as provide context to the user on the address.

Performance

Starting with version 2.0.0, aslookup uses asynchronous DNS lookups to improve performance when processing multiple IP addresses. The tool automatically processes multiple addresses concurrently (up to 15 simultaneous requests by default) while maintaining the same CLI interface and output format.

Installation

The app has been tested on Python 3.

It's best to install the program into a Python virtualenv. If you will only use the command line interface, the recommended way to install it is using pipx:

pipx install aslookup

If you will use aslookup as a library, you'll instead want to install it using pip in your target Python environment:

python3 -m pip install aslookup

Usage

Python module

The Python module defaults to querying the Team Cymru data service. The desired service may be specified by passing the service parameter to get_as_data.

from aslookup import get_as_data
ip = "8.8.8.8"
get_as_data(ip, service="shadowserver")

CLI script

It is possible to provide multiple IP addresses as arguments to the script, or to send them as a list on standard input, in which cases the script loops over them and returns output on separate lines. When providing invalid IP addresses as arguments, the script reports the problem on standard error and exits with an error. When providing input on stdin, the error is reported on standard output but execution is not aborted.

as-lookup 8.8.8.8 9.9.9.9
as-lookup 2001:4860:4860::8888 2001:4860:4860::8844

or:

as-lookup < ipaddrs.txt

Test data

A list of test values for the script is included in the file tests/test_input.txt. This can be useful to validate included IP prefix classifications and see the output format.

as-lookup < tests/test_input.txt

Metadata

Release files for aslookup 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aslookup 2.0.0
File Size Uploaded
aslookup-2.0.0.tar.gz 18.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aslookup 2.0.0
File Interpreter ABI Platform
aslookup-2.0.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 29.3 kB

Release files / aslookup-2.0.0.tar.gz

Download URL aslookup-2.0.0.tar.gz
Size 18.9 kB
Tags Source
SHA-256 checksum
How to use checksums
401872be15f3d483529d63956d9bcd343b043b86efa41468a6440db0564751e6
BLAKE2b-256 checksum
How to use checksums
a427bdedbc8a77cc156395524c84fafb3b2416b6a4d417485a7bc13c114442b0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.2

Release files / aslookup-2.0.0-py2.py3-none-any.whl

Download URL aslookup-2.0.0-py2.py3-none-any.whl
Size 10.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
915bf4cfb70b8ce17a6c183f3851ac07e60aacd711bd33287dae34102e442420
BLAKE2b-256 checksum
How to use checksums
3b295464eaa81b77a20737120e051368e2705ca011b14e411480bdc08f4e1d1b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.2

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files

1.7.0

2 release files

1.6.1

2 release files

1.6.0

2 release files

1.5.1

2 release files

1.5.0

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.3

2 release files

1.0.2

2 release files

0.20

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page