Git Product home page Git Product logo

ipparser's Introduction

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

ipparser's People

Contributors

m8sec avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.