def test_valid_nmap_range_with_valid_target_specs(): assert valid_nmap_range('192.0.2.1') assert valid_nmap_range('192.0.2.0-31') assert valid_nmap_range('192.0.2-3.1-254') assert valid_nmap_range('0-255.0-255.0-255.0-255') assert valid_nmap_range('192.168.3-5,7.1') assert valid_nmap_range('192.168.3-5,7,10-12,13,14.1') assert valid_nmap_range('fe80::1') assert valid_nmap_range('::') assert valid_nmap_range('192.0.2.0/24')
def config_create(): #create config file with json format global allow_remoteport global allow_trustzone port = raw_input("input listen port (80,443...): ") portlist = port.split(",") for i in portlist: try: a = int(i) except ValueError: print "listen port range is 1-65535" exit(1) if a < 0 or a > 65535: print "error input: " + i exit(1) zone = raw_input("input trust zones (192.168.1.1/24,172.16.31.1/24): ") zonelist = zone.split(",") for i in zonelist: if not netaddr.valid_nmap_range(i): print "error input: " + i exit(1) config_dict = {} config_dict["port"] = portlist config_dict["zone"] = zonelist allow_remoteport = portlist allow_trustzone = zonelist with open("config.json", "w") as f: json.dump(config_dict, f, sort_keys=True, indent=4)
def parse_target_hosts(self, hosts, port): """Parses a list of hosts""" if netaddr: if netaddr.valid_nmap_range(hosts): for ip in netaddr.iter_nmap_range(hosts): yield (str(ip), port) else: for ip in netaddr.iter_unique_ips(hosts): yield (str(ip), port) else: yield (hosts, port)
def parse_target_hosts(target_hosts, target_ports): for port in target_ports.split(','): for host in target_hosts.split(','): if netaddr: if netaddr.valid_nmap_range(host): for ip in netaddr.iter_nmap_range(host): yield (ip, port) else: for ip in netaddr.iter_unique_ips(host): yield (ip, port) else: yield(host, port)
def parse_target_hosts(target_hosts, target_ports): for port in parse_target_ports(target_ports): for host in target_hosts.split(','): if netaddr: if netaddr.valid_nmap_range(host): for ip in netaddr.iter_nmap_range(host): yield (ip, port) else: for ip in netaddr.iter_unique_ips(host): yield (ip, port) else: yield (host, port)
def get_ip_range(self, ip_block): ip_range = None if netaddr.valid_nmap_range(ip_block): ip_range = list(netaddr.iter_nmap_range(ip_block)) else: try: ip_range = netaddr.IPGlob(ip_block) except netaddr.AddrFormatError: try: ip_range = netaddr.IPNetwork(ip_block) except netaddr.AddrFormatError: pass return ip_range
def test_valid_nmap_range_with_invalid_target_specs(): assert not valid_nmap_range('192.0.2.0/255.255.255.0') assert not valid_nmap_range(1) assert not valid_nmap_range('1') assert not valid_nmap_range([]) assert not valid_nmap_range({}) assert not valid_nmap_range('fe80::/64') assert not valid_nmap_range('255.255.255.256') assert not valid_nmap_range('0-255.0-255.0-255.0-256') assert not valid_nmap_range('0-255.0-255.0-255.-1-0') assert not valid_nmap_range('0-255.0-255.0-255.256-0') assert not valid_nmap_range('0-255.0-255.0-255.255-0') assert not valid_nmap_range('a.b.c.d-e') assert not valid_nmap_range('255.255.255.a-b')