Skip to main content

Parse IP address information and return a list for iteration.

Project description

IPParser

The IPParser Python module was created to simplify accepting IPv4 addresses, DNS names, and target / host information when creating other security or network tools. User inputs are taken and parsed to provide a list of IPv4 addresses or DNS names that can be used for iteration. If called with resolve=True, ipparser will attempt to perform "A" record lookups and returns all IP addresses found for 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,m8r0wn.com)
  • CIDR Ranges /8-/32 (192.168.1.0/24)
  • URL's (https://m8r0wn.com/demo)
  • IP:Port (192.168.1.1:8080)
  • DNS Names (m8r0wn.com)
  • TXT files (Containing any of the items listed)
  • Nmap XML Reports

Install

pip3 install ipparser

OR

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

Usage:

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

  • resolve=False - Resolve any DNS names identified, to IPv4 addresses, and append to output.
  • open_ports=False - Return IP:Port notation for all open ports found (Nmap XML only)
  • silent=False - Do not show errors while parsing.
  • exit_on_error=True - Exit on errors found while parsing user input.
  • debug=False - Show input classification for debugging.

Examples

>>> 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)
['98.138.219.232', '98.138.219.231', '72.30.35.9', '72.30.35.10', '98.137.246.7', '98.137.246.8']

>>> ipparser('example', resolve=True, exit_on_error=False)
IPParser Error: Invalid or unsupported input provided 'example'

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

ipparser('192.168.1.1,yahoo.com,example', resolve=True, exit_on_error=False)
IPParser Error: Invalid or unsupported input provided 'example'
['192.168.1.1', '98.138.219.231', '98.137.246.8', '98.137.246.7', '72.30.35.9', '98.138.219.232', '72.30.35.10']

>>> ipparser('192.168.1.1,yahoo.com,example', resolve=True, silent=True)
['192.168.1.1', '72.30.35.10', '98.138.219.231', '98.137.246.7', '98.137.246.8', '72.30.35.9', '98.138.219.232']

Argparse Integration

  • Standard Argument:
from ipparser import ipparser
from argparse import ArgumentParser

args = ArgumentParser(description='ipparser integration with argparse')
args.add_argument('-host', dest='host', default=False, type=lambda x: ipparser(x), help='Host Input')
args = args.parse_args()
Namespace(host=['192.168.1.1'])
  • Required Positional Argument (Method 1):
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']])
  • Required Positional Argument (Method 2):
from ipparser import ipparser
from argparse import ArgumentParser

args = ArgumentParser(description='ipparser integration with argparse')
args.add_argument(dest='positional_host', nargs='+', help='Host Input')
args = args.parse_args()
args.positional_host = ipparser(args.positional_host[0]) 
positional_host=['192.168.1.1'])
  • Allow user args to determine resolve setting:
from sys import argv
from ipparser import ipparser
from argparse import ArgumentParser

r = False
if "-r" in argv:
    r = True

args = ArgumentParser(description='ipparser integration with argparse')
args.add_argument('-r', dest='resolve',action='store_true', help='Resolve input DNS hosts')
args.add_argument(dest='positional_host', nargs='+', type=lambda x: ipparser(x, resolve=r), help='Host Input')
args = args.parse_args()

Sys.argv Usage

  • Standard Argument
from sys import argv
from ipparser import ipparser

if "-host" in argv:
    host = ipparser(argv[argv.index("-host") + 1])
host = ['192.168.1.1']
  • Positional Argument
from sys import argv
from ipparser import ipparser

host = ipparser(argv[-1])
host = ['192.168.1.1']

Contributors

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-0.3.8.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

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

ipparser-0.3.8-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ipparser-0.3.8.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.9.1

File hashes

Hashes for ipparser-0.3.8.tar.gz
Algorithm Hash digest
SHA256 f311dac4e9644080c53f525105a8e65fb2f83412b678a6e7785dfcbbdf9574fc
MD5 4d32bf2f43f535ff4937c427d559418c
BLAKE2b-256 a0147b6124565ac0fc52f77c286d315aca0791a10a752d8b353560fcc8cb3379

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ipparser-0.3.8-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.9.1

File hashes

Hashes for ipparser-0.3.8-py3-none-any.whl
Algorithm Hash digest
SHA256 4fb02350b3d38446fe713d5ad7964c2de8b1e382a2fa7bbcc6de9d93c6ffd54c
MD5 89c53116498737d3425ce6d229bee25c
BLAKE2b-256 e0ab26803f6c14b9044eedcec8ec841e96284142cd59048f60c7efd09eb01fec

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