Skip to main content

Objective

A python class to search ip2asn information for matches.

See the pretty documentation over on readthedocs.

Installation

Using pip or pipx:

pipx install ip2asn

Example Usage

setup

ip2asn -f ip2asn.db --fetch

command line

Searching for an address

# ip2asn 8.8.8.8

Address: 8.8.8.8
  Numeric ip: 134744072
         ASN: 15169
       Owner: GOOGLE - Google LLC
     Country: US
    ip_range: 8.8.8.0 - 8.8.8.255

Searching for an ASN

# ip2asn -a 15169

         ASN: 15169
       Owner: GOOGLE
     Country: US
    ip_range: 8.8.4.0 - 8.8.4.255

         ASN: 15169
       Owner: GOOGLE
     Country: US
    ip_range: 8.8.8.0 - 8.8.8.255

         ASN: 15169
       Owner: GOOGLE
...
(google has a lot of registrations)

Displaying a tcpdump / libpcap filter given a address or ASN

# ip2asn -T -a 15169
( net 8.8.4.0/24 or net 8.8.8.0/24 or net 8.35.200.0/21 or ....

Coding

Searching by IP address

import ip2asn
i2a = ip2asn.IP2ASN("ip2asn-v4-u32.tsv")
result = i2a.lookup_address("93.184.216.34")

import pprint
pprint.pprint(result)

Produces:

{'ASN': '15133',
 'country': 'US',
 'ip_numeric': 1572395042,
 'ip_range': [1572394752, 1572396543],
 'ip_text': '93.184.216.34',
 'owner': 'EDGECAST - MCI Communications Services, Inc. d/b/a Verizon Business'}

Searching by ASN

import ip2asn
i2a = ip2asn.IP2ASN("ip2asn-combined.tsv")
results = i2a.lookup_asn(15169, limit=2)  # limit is optional

import pprint
pprint.pprint(results)
``**

**Produces:**

``` text
[{'ASN': '15169',
  'country': 'US',
  'ip_range': [134743040, 134743295],
  'owner': 'GOOGLE - Google LLC'},
 {'ASN': '15169',
  'country': 'US',
  'ip_range': [134744064, 134744319],
  'owner': 'GOOGLE - Google LLC'}]

Author

Wes Hardaker, USC/ISI

Metadata

Release files for ip2asn 1.8

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

Built distribution (wheel)

Table of built distributions (wheels) for ip2asn 1.8
File Interpreter ABI Platform Actions
ip2asn-1.8-py3-none-any.whl Python 3 none any Details for ip2asn-1.8-py3-none-any.whl

Release files / ip2asn-1.8-py3-none-any.whl

Download URL ip2asn-1.8-py3-none-any.whl
Size 12.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
82506abe6ed222dd616a02d4d9ec4836b773a487e235f3a7d04b8e4e17620cbe
BLAKE2b-256 checksum
How to use checksums
d2c01a814760aa5a6bf3c92f140cd5543cc4f0d3fdd592b5a14ef8865871879e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.9

Security for ip2asn 1.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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