Skip to main content

A lightweight, modern, robust IP info CLI tool

Project description

IP Lens CLI Tool

A lightweight CLI tool designed for fetching and displaying detailed IP address information. No API keys are required, making it accessible and easy to use for various use cases.

IP Lens CLI Tool Screenshot

Installation

Install via pip

You can install the IP Lens CLI tool directly from PyPI:

pip install iplens

Install from source

To build and install the tool from source:

Clone the repository:

git clone https://github.com/aiomorphic/iplens.git
cd iplens
pip install -e .

Usage

CLI Tool

Basic usage:

iplens 8.8.8.8 1.1.1.1

Using an input file:

iplens --input-file ips.txt

The input file can be in one of the following formats:

  • Plain text file with one IP address per line
  • Text file containing a Python list of IP addresses
  • JSON file with a list of IP addresses or a dictionary containing a list of IP addresses in any field
  • CSV file with a column containing IP addresses (the column name should include "ip", case-insensitive)
  • Log file containing IP addresses (the tool will extract unique IP addresses from the log)

Using an Input Folder to Parse Files for IP Addresses:

You can also specify a directory, and the tool will parse all non-binary files within that folder to extract IP addresses:

iplens --input-folder /path/to/logs/

Use Cases:

Scan system logs: For example, to scan the UFW log for IP addresses, you can run:

iplens --input-folder /var/log/ufw.log

or for e.g. analyze web server logs: Parse your web server logs to gather and analyze IP addresses.

Save output to a file:

iplens 8.8.8.8 1.1.1.1 --output results --format json

Available options:

  • --input-file or -i: Specify an input file containing IP addresses
  • --input-folder or -d: Specify an input folder containing files to parse for IP addresses
  • --output or -o: Specify output file (without extension)
  • --format or -f: Specify output format (csv or json)

Note: The tool will automatically detect the input file format and extract valid IP addresses. Invalid IP addresses will be ignored.

Exports Examples

[
  {
    "ip": "8.8.8.8",
    "rir": "ARIN",
    "is_bogon": "False",
    "is_datacenter": "True",
    "is_tor": "False",
    "is_proxy": "False",
    "is_vpn": "True",
    "is_abuser": "True",
    "company_name": "Google LLC",
    "company_abuser_score": "0.0039 (Low)",
    "company_type": "business",
    "company_domain": "google.com",
    "company_network": "8.8.8.0 - 8.8.8.255",
    "company_whois": "https://api.incolumitas.com/?whois=8.8.8.0",
    "abuse_email": "network-abuse@google.com",
    "asn_asn": "AS15169",
    "asn_abuser_score": "0 (Very Low)",
    "asn_route": "8.8.8.0/24",
    "asn_descr": "GOOGLE, US",
    "asn_country": "us",
    "asn_active": "True",
    "asn_org": "Google LLC",
    "asn_domain": "google.com",
    "asn_abuse": "network-abuse@google.com",
    "asn_type": "business",
    "asn_created": "2000-03-30",
    "asn_updated": "2012-02-24",
    "asn_rir": "ARIN",
    "asn_whois": "https://api.incolumitas.com/?whois=AS15169",
    "location_country": "United States",
    "location_country_code": "US",
    "location_state": "California",
    "location_city": "Sunnyvale",
    "location_latitude": "37.36883",
    "location_longitude": "-122.03635",
    "location_zip": "95196",
    "location_timezone": "America/Los_Angeles"
  }
]
ip,rir,is_bogon,is_datacenter,is_tor,is_proxy,is_vpn,is_abuser,company_name,company_abuser_score,company_type,company_domain,company_network,company_whois,abuse_email,asn_asn,asn_abuser_score,asn_route,asn_descr,asn_country,asn_active,asn_org,asn_domain,asn_abuse,asn_type,asn_created,asn_updated,asn_rir,asn_whois,location_country,location_country_code,location_state,location_city,location_latitude,location_longitude,location_zip,location_timezone
8.8.8.8,ARIN,False,True,False,False,True,True,Google LLC,0.0039 (Low),business,google.com,8.8.8.0 - 8.8.8.255,https://api.incolumitas.com/?whois=8.8.8.0,network-abuse@google.com,AS15169,0 (Very Low),8.8.8.0/24,"GOOGLE, US",us,True,Google LLC,google.com,network-abuse@google.com,business,2000-03-30,2012-02-24,ARIN,https://api.incolumitas.com/?whois=AS15169,United States,US,California,Sunnyvale,37.36883,-122.03635,95196,America/Los_Angeles

As a Python Library

IP Lens can also be utilized as a Python library for direct integration into your Python projects.

from iplens.api import IPInfoAPI

api = IPInfoAPI()
results = api.process(['8.8.8.8', '1.1.1.1'])

This will fetch and process the IP information for the given IP addresses. The results will include detailed information such as ASN, location, company details, and more, extracted and formatted for easy access

Configuration

The configuration file is located at src/iplens/config.cfg. You can modify the configuration file to suit your specific requirements. The available fields and their purposes are defined in the src/config_loader.py.

API Limits

Note that the API has rate limits in its free, unregistered mode. If you encounter a rate limit, simply wait for 20 minutes and then continue using the tool.

Caching

IP Lens includes a caching mechanism to store fetched IP information locally. This helps reduce the number of API calls, especially when processing large lists of IPs. The cache is automatically cleared after a configurable expiration period, which can be set in the config.cfg file.

Ignoring Fields

If there are specific fields you wish to exclude from the output, you can configure this in the src/utils.py file, where the list of field names is defined. This allows you to customize the output based on your needs.

Development

Setup

  1. Clone the repository
    git clone https://github.com/aiomorphic/iplens.git
    cd iplens
    
  2. Create a virtual environment: python -m venv venv
  3. Activate the virtual environment:
    • Windows: venv\Scripts\activate
    • Unix or MacOS: source venv/bin/activate
  4. Install development dependencies: pip install -r requirements.txt

Pre commit checks

make pre-commit

Adding New Features

Implement new functionality in the appropriate module under iplens/. Add tests for the new functionality in tests/. Update iplens_cli.py if the new feature should be accessible via CLI.

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

iplens-0.1.7.tar.gz (16.7 kB view details)

Uploaded Source

Built Distribution

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

iplens-0.1.7-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file iplens-0.1.7.tar.gz.

File metadata

  • Download URL: iplens-0.1.7.tar.gz
  • Upload date:
  • Size: 16.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for iplens-0.1.7.tar.gz
Algorithm Hash digest
SHA256 1de6ef0945ad25657ee72e22f06b188fef058257eff33782b14dfecf520f0034
MD5 3f22aec9bbd2e770592b0e3406bc3f50
BLAKE2b-256 7175045e8151ff344ca60f22982dc5f53aa18442883a3540265bb3f4db2fb6ca

See more details on using hashes here.

File details

Details for the file iplens-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: iplens-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 14.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for iplens-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 6f13def33b646cd47a9eab3c976821311a32a78a42dd672e49b7e22ff3659278
MD5 75c15fb4ea6c0aabd7c3d9b842dc7049
BLAKE2b-256 e1128ed89da3a70a16c9632439ad2bc6c519692906283b4744546ca151e12a62

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