Skip to main content

IP to ASN routing data query script

Project description

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 currently done using DNS, which works well for a one-off lookups. It is not optimized for bulk lookups over the Whois protocol.

Currently only IPv4 addresses are looked up. The client also maintains a listing of IP networks which are unroutable internet addresses, typically special use ranges in RFCs. 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.

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 IPv4 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

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aslookup-1.4.0.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aslookup-1.4.0-py2.py3-none-any.whl (8.2 kB view details)

Uploaded Python 2Python 3

File details

Details for the file aslookup-1.4.0.tar.gz.

File metadata

  • Download URL: aslookup-1.4.0.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for aslookup-1.4.0.tar.gz
Algorithm Hash digest
SHA256 af215170a587e4abe1577d4c2078968ecfca9c983883bbaa05383dcb02cd1440
MD5 6d5700e9a1d1d7c6cb475b6f8fdd1225
BLAKE2b-256 80d534db45abe47c6801ba0f5a86de2f3cde4b03742600f5e91e2b62746f29c5

See more details on using hashes here.

File details

Details for the file aslookup-1.4.0-py2.py3-none-any.whl.

File metadata

  • Download URL: aslookup-1.4.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for aslookup-1.4.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c005d281f8f3a94d7c49e5a34e9551adc15d8d79f253d633db4648667456bc50
MD5 74222405f1002200ee2242f2d0cd3ee8
BLAKE2b-256 d2b0f1c14968671c0866275100981bc2e3c74c1396cb85524bb969e391278091

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page