Skip to main content

Lightweight package to parse host inputs for iteration.

Project description

IPParser

The IPParser Python library was created to simplify accepting IP addresses, DNS names, and target / host information in security or network based tooling.

User inputs are parsed to provide an iterable list for further action. If called with resolve=True, ipparser will attempt to perform an "A" record lookup and return the first resolved address associated with the host.

Inputs:

IPParser currently accepts the following user inputs:

  • Single IP (192.168.1.10)
  • IP ranges (192.168.1.1-55)
  • Multiple IP's (192.168.1.3,192.168.1.7,m8sec.dev)
  • CIDR Ranges /8-/32 (192.168.1.0/24)
  • URL's (https://m8sec.dev)
  • IP:Port (192.168.1.1:8080)
  • DNS Names (m8sec.dev)
  • TXT files (Containing any of the items listed)
  • Nmap XML Reports
  • Read from STDIN

Install

pip3 install ipparser

OR

git clone https://github.com/m8sec/ipparser
cd ipparser
python3 setup.py install

(Primary) Usage:

The IPParser function can be called with the following arguments (shown with their default values):

  • open_ports=False - Return IP:Port notation for all open ports found (Nmap XML only)
  • exit_on_error=True - Exit on error while parsing user input.
  • resolve=False - Resolve any DNS names identified, to IPv4 addresses, and append to output.
  • ns=[] - Define name servers for DNS lookups.

Examples

Standard Usage

>>> from ipparser import ipparser
>>> ipparser('192.168.1.3-5')
['192.168.1.3', '192.168.1.4', '192.168.1.5']

>>> ipparser('yahoo.com',resolve=True)
['74.6.143.26']


>>> ipparser('192.168.1.1,yahoo.com')
['192.168.1.1', 'yahoo.com']

Argparse Integration - Required Positional Argument:

from ipparser import ipparser
from argparse import ArgumentParser

args = ArgumentParser(description='ipparser integration with argparse')
args.add_argument(dest='positional_host', nargs='+', type=lambda x: ipparser(x, resolve=False), help='Host Input')
args = args.parse_args()
Namespace(positional_host=[['192.168.1.1']])

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

ipparser-1.0.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

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

ipparser-1.0.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file ipparser-1.0.0.tar.gz.

File metadata

  • Download URL: ipparser-1.0.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for ipparser-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f1d6558a7b8455ac29e378b42b38242dded8a1a80d17ef3d37c7a845ee95b290
MD5 74ce28903c64ee59afc80e922a0c0c99
BLAKE2b-256 33f8698f4cb78668590f910cd40fe4353b8dfa6d75d600a0df29e238386beba2

See more details on using hashes here.

File details

Details for the file ipparser-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: ipparser-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for ipparser-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b48bf5aef2f341862d6d830554907af801a56be1d20d58e9100533c96cd7bec0
MD5 7d8bef24d303c8983cf99c95a951f97a
BLAKE2b-256 e97c6810bdc58c9fbbfd064290bf59138ae27ff9198df8bbcd70bbefddb407ce

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