diff --git a/network_list_from_netname.py b/network_list_from_netname.py index 255f27f..ff11a09 100755 --- a/network_list_from_netname.py +++ b/network_list_from_netname.py @@ -30,13 +30,13 @@ def extract_netname(filename_or_url): if re.match(r'^netname:', line): netname = line.split(':')[1].strip() response = whois_query(netname, "inetnum") - if response is not None: + if response is not None and len(response) > 0: if not args.quiet: print(f"# Network name: {netname}") - ip_range = response.strip() - cidrs = convert_to_cidr(ip_range) - for cidr in cidrs: - print(cidr) + for cidr in response: + net = convert_to_cidr(cidr) + net = net[0] + print(net) return None diff --git a/pylib/whois.py b/pylib/whois.py index 9d304d7..e46cad6 100755 --- a/pylib/whois.py +++ b/pylib/whois.py @@ -22,12 +22,18 @@ def whois_query(query, get_field="netname", get_org=False): s.close() org_name = None - basic_name = None + if get_field == "inetnum": + basic_name = [] + else: + basic_name = None for line in response.split('\n'): if line.startswith('org-name' + ':'): org_name = line.split(':')[1].strip() if line.startswith(get_field + ':'): - basic_name = line.split(':')[1].strip() + if get_field == "inetnum": + basic_name.append(line.split(':')[1].strip()) + else: + basic_name = line.split(':')[1].strip() if basic_name is None: basic_name = '-no-description-' @@ -36,6 +42,6 @@ def whois_query(query, get_field="netname", get_org=False): org_name = 'No org name found' if get_org is True: - return basic_name + ' (' + org_name + ')' + return str(basic_name) + ' (' + org_name + ')' else: return basic_name