A python class to quickly search ip2asn data for range matches
Project description
Objective
A python class to search ip2asn information for matches.
Installation
Using pip:
pip3 install ip2asn
Or manually:
git clone git@github.com:hardaker/ip2asn.git
cd ip2asn
python3 setup.py build
python3 setup.py install
Example Usage
setup
curl -o ip2asn-v4-u32.tsv.gz https://iptoasn.com/data/ip2asn-v4-u32.tsv.gz
gunzip ip2asn-v4-u32.tsv.gz
command line
Searching for an address
# ip2asn -f ip2asn-v4-u32.tsv 8.8.8.8
Address: 8.8.8.8
Numeric ip: 134744072
ASN: 15169
Owner: GOOGLE - Google LLC
Country: US
ip_range: [134744064, 134744319]
Searching for an ASN
# ip2asn -f ip2asn-v4-u32.tsv -a 15169
ASN: 15169
Owner: GOOGLE - Google LLC
Country: US
ip_range: [134743040, 134743295]
ASN: 15169
Owner: GOOGLE - Google LLC
Country: US
ip_range: [134744064, 134744319]
ASN: 15169
Owner: GOOGLE - Google LLC
...
(google has a lot of registrations)
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-v4-u32.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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ip2asn-1.2.2.tar.gz
(4.8 kB
view details)
Built Distribution
File details
Details for the file ip2asn-1.2.2.tar.gz
.
File metadata
- Download URL: ip2asn-1.2.2.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.2 pkginfo/1.4.2 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7dae9d56a2df15f251a9981d59c6d73f99e07ce22f1646d4903cde0ee6b634e |
|
MD5 | 241f01e63511f07acddf58d371f4a189 |
|
BLAKE2b-256 | 7ab00678c35f1ea3d190bfb278324e04c49f03905dc0d767554c1ac2c79e86bc |
File details
Details for the file ip2asn-1.2.2-py3-none-any.whl
.
File metadata
- Download URL: ip2asn-1.2.2-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.2 pkginfo/1.4.2 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 019c41eb65e140a88c78e5b90b19b0202095472753849b265084391754b12113 |
|
MD5 | 277239ab4f9d8e7aa46ebb1a6dff0245 |
|
BLAKE2b-256 | 672e8cc60e38e61d3b4dc1c39fda8f0a54ae064cdd4de47775f8c47a7deadfe4 |