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

Release files for ip2asn 1.6.6

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

Source distribution (sdist)

Source distribution for ip2asn 1.6.6
File Size Uploaded
ip2asn-1.6.6.tar.gz 10.0 kB Details

Built distribution (wheel)

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

Total release size: 22.1 kB

Release files / ip2asn-1.6.6.tar.gz

Download URL ip2asn-1.6.6.tar.gz
Size 10.0 kB
Tags Source
SHA-256 checksum
How to use checksums
2b326abc46c8de4874909b4449467a726622e37a8e59cafde42dd92744d2416d
BLAKE2b-256 checksum
How to use checksums
fc7f0340d62710e75a776b748934ffad01f2ab1d16f7473600fde22e8da5bfec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.27.0

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

Download URL ip2asn-1.6.6-py3-none-any.whl
Size 12.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f15c6d59ad4a8c1fb8986b21ffeb004aa02fac08d736d90397302b19aa7a7d96
BLAKE2b-256 checksum
How to use checksums
a73d16b3283c4669155bd8ccc37f0d22f678f0ffe998068717ddbfa16591def3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.27.0

Release history Release notifications | RSS feed

This release

1.6.6 This release

2 release files

1.6.5

2 release files

1.6.4

2 release files

1.6.3

2 release files

1.6.2

2 release files

1.6.1

2 release files

1.6

2 release files

1.4

2 release files

1.3.1

2 release files

1.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2

2 release files

1.1

2 release files

1.0.1

2 release files

1.0

2 release files

0.9

2 release files

0.5.1

2 release files

0.5

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