Metadata-Version: 2.3
Name: ip2asn
Version: 1.6.5
Summary: Quickly look up ownership information about IP addresses
Project-URL: Homepage, https://github.com/hardaker/ip2asn
Author-email: Wes Hardaker <opensource@hardakers.net>
License: MIT License
        
        Copyright (c) 2020-2025 University of Southern California, Information Sciences Institute
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.7
Requires-Dist: msgpack
Requires-Dist: pyfsdb
Requires-Dist: requests
Description-Content-Type: text/markdown

# Objective

A python class to search [ip2asn] information for matches.

[ip2asn]: https://iptoasn.com/

See the [pretty documentation] over on *readthedocs*.

[pretty documentation]: https://ip2asn.readthedocs.io/en/latest/

# Installation

Using pip or pipx:

```
pipx install ip2asn
```

# Example Usage

## setup

``` sh
ip2asn -f ip2asn.db --fetch
```

## command line

### Searching for an address

``` sh
# 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

``` sh
# 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

``` sh
# 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:**

``` text
{'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

``` python
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

