def network_validator(self, network): try: ipaddr.IPNetwork(network) except Exception as e: raise Exception( "Please validate your subnet. Valid input: 192.168.0.0/24") return True
def __init__(self, subnet=None, config_in=None, threads=4, shuffle=False, verbose=False): super(pingSweep, self).__init__(verbose=verbose) if subnet is not None: try: self.subnet_raw = subnet self.subnet = list(ipaddr.IPNetwork(subnet)) except: raise Exception( 'Please ensure your subnet is in proper format: 192.168.1.0/24' ) # TODO ADD NOSTRIKE AND MAKE OUTPUT FOR SCANNER NESSUS COMPATIBLE (IP,\n,IP) self.threads = threads self.queue = Queue() self.alive = 0 self.alive_hosts = [] self.shuffle = random self.it = Interact() self.root_check = self.it.root_check(debug=False) self.parse_args() self.config_in = config_in self.shuffle = shuffle self.verbose = verbose print config_in if config_in is not None: self.configs = config(config=config_in, VERBOSE=self.verbose) #Validation(config_in, verbose=self.verbose).validate() self.target_ranges = self.configs.configs.get('target_range', '') self.trusted_range = self.configs.configs.get('trusted_range', '') self.nostrike = self.configs.configs.get('nostrike', '') else: #print("[-] Please specify a configuration path!") self.nostrike = None self.GREEN_PLUS = "[{green}+{endc}]".format(green=bcolors.OKGREEN, endc=bcolors.ENDC) self.WARN = "[{red}!{endc}]".format(red=bcolors.WARNING, endc=bcolors.ENDC) self.INFO = "[{obc}INFO{endc}]".format(obc=bcolors.OKBLUE, endc=bcolors.ENDC)
def pinger(self, i, q): """PING SUBNET""" nostrike = None # ACCOUNTS FOR IPS IN NO STRIKE -- THEY WILL NOT BE TOUCHED if self.nostrike: nostrike = [ str(x) for b in self.nostrike for x in ipaddr.IPNetwork(b) ] while True: ip = q.get() if nostrike and ip not in nostrike: ret = subprocess.call("ping -c 1 %s" % ip, shell=True, stdout=open('/dev/null', 'w'), stderr=subprocess.STDOUT) if ret == 0: print('{gp} {ip} is alive'.format(gp=self.GREEN_PLUS, ip=str(ip))) self.alive += 1 self.alive_hosts.append(str(ip)) q.task_done() return