From d2ecbfd8d8706f82bc00bdcbad8e42ebc7c3bad7 Mon Sep 17 00:00:00 2001 From: ProDigySML Date: Sat, 5 Jan 2019 22:42:21 -0800 Subject: [PATCH 1/3] Added in sml555 twitter badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4f16067..eaa96fe 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Interlace A threading management application that allows controlled execution of multiple commands, over multiple targets. -[![Python 3.2|3.6](https://img.shields.io/badge/python-3.2|3.6-green.svg)](https://www.python.org/) [![License](https://img.shields.io/badge/license-GPL3-_red.svg)](https://www.gnu.org/licenses/gpl-3.0.en.html) [![Build Status](https://travis-ci.org/codingo/Reconnoitre.svg?branch=master)](https://travis-ci.org/codingo/Reconnoitre) [![Twitter](https://img.shields.io/badge/twitter-@codingo__-blue.svg)](https://twitter.com/codingo_) +[![Python 3.2|3.6](https://img.shields.io/badge/python-3.2|3.6-green.svg)](https://www.python.org/) [![License](https://img.shields.io/badge/license-GPL3-_red.svg)](https://www.gnu.org/licenses/gpl-3.0.en.html) [![Twitter](https://img.shields.io/badge/twitter-@codingo__-blue.svg)](https://twitter.com/codingo_) [![Twitter](https://img.shields.io/badge/twitter-@sml555_-blue.svg)](https://twitter.com/sml555_) # Contributions Contributions to this project are very welcome. If you're a newcomer to open source and would like some help in doing so, feel free to reach out to me on twitter ([@codingo_](https://twitter.com/codingo_)) and I'll assist wherever I can. From 8eff132e8f2eaf737adbfd97cdc13e4b7a3fdd32 Mon Sep 17 00:00:00 2001 From: ProDigySML Date: Sat, 5 Jan 2019 22:57:24 -0800 Subject: [PATCH 2/3] Added netaddr for CIDR handling --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 1bda004..fce9844 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ colorclass==2.2.0 +netaddr==0.7.19 \ No newline at end of file From 8484ac64ba4a1ad98837224b117df80855b2c2b3 Mon Sep 17 00:00:00 2001 From: ProDigySML Date: Sun, 6 Jan 2019 00:49:25 -0800 Subject: [PATCH 3/3] Added in CIDR, ranges, and glob ranges --- Interlace/lib/core/input.py | 63 ++++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 7 deletions(-) diff --git a/Interlace/lib/core/input.py b/Interlace/lib/core/input.py index 9179c68..42088c7 100644 --- a/Interlace/lib/core/input.py +++ b/Interlace/lib/core/input.py @@ -1,4 +1,5 @@ from argparse import ArgumentParser +from netaddr import IPNetwork, IPRange, IPGlob import os.path @@ -18,25 +19,73 @@ class InputHelper(object): return arg + @staticmethod + def _get_ips_from_range(ip_range): + ips = set() + ip_range = ip_range.split("-") + + # parsing the above structure into an array and then making into an IP address with the end value + end_ip = ".".join(ip_range[0].split(".")[0:-1]) + "." + ip_range[1] + + # creating an IPRange object to get all IPs in between + range_obj = IPRange(ip_range[0], end_ip) + + for ip in range_obj: + ips.add(str(ip)) + + return ips + + @staticmethod + def _get_ips_from_glob(glob_ips): + ip_glob = IPGlob(glob_ips) + + ips = set() + + for ip in ip_glob: + ips.add(str(ip)) + + return ips + + @staticmethod + def _get_cidr_to_ips(cidr_range): + ips = set() + + for ip in IPNetwork(cidr_range): + ips.add(str(ip)) + + return ips + @staticmethod def process_commands(arguments): commands = set() + ranges = set() targets = set() final_commands = set() # process targets first if arguments.target: - targets.add(arguments.target) + ranges.add(arguments.target) else: for target in arguments.target_list: - targets.add(target.strip()) + ranges.add(target.strip()) - # todo: take list of targets and expand CIDR / comma notation - if not arguments.nocidr: - # todo: expand CIDR from net addr - pass + # removing elements that may have spaces (helpful for easily processing comma notation) + for target in ranges: + target = target.replace(" ", "") - # todo: expand comma notation + # todo: take list of targets and expand CIDR / comma notation + for ips in target.split(","): + # checking for CIDR + if not arguments.nocidr and "/" in ips: + targets.update(InputHelper._get_cidr_to_ips(ips)) + # checking for IPs in a range + elif "-" in ips: + targets.update(InputHelper._get_ips_from_range(ips)) + # checking for glob ranges + elif "*" in ips: + targets.update(InputHelper._get_ips_from_glob(ips)) + else: + targets.add(ips) if arguments.command: commands.add(arguments.command)