Commit fe4b48c0 authored by Sven Van Dyck's avatar Sven Van Dyck

See #1

parent cfed1905
Pipeline #44279 passed with stage
in 4 minutes and 30 seconds
......@@ -11,6 +11,8 @@ from typing import Counter, Dict, List, Iterable, Iterator, NamedTuple, Set, Uni
import dns.name
import ipaddress
class EDNSResult(IntEnum):
"""
EDNS evaluation result for single zone
......@@ -58,10 +60,17 @@ def eval_edns_nsset(nsips: Iterable[str], nsstats: Dict[str, Counter[EDNSResult]
"""combined result for the whole nsset"""
set_results = []
for ip in nsips:
#try: # this is an error in ednscomp input generation
set_results.append(eval_edns_ip(nsstats[ip]))
#except KeyError as ex:
# print('IP {} not found in ednscomp stats'.format(ip))
#print (str(ip))
if ip.startswith("::ffff"):
#Convert this to match how genreport manipulates such an ip
#print (ip)
ip=ipaddress.ip_address(ip).ipv4_mapped
ip="::ffff:" + str(ip)
try: # this is an error in ednscomp input generation
set_results.append(eval_edns_ip(nsstats[ip]))
except KeyError as ex:
print('ERROR ERROR: IP {} not found in ednscomp stats'.format(ip))
if len(set_results) == 0:
raise KeyError('no IPs')
......@@ -165,7 +174,7 @@ class ResultTable():
return '\n'.join(lines)
@property
def text(self) -> str:
def text(self) -> str:
output = '{:13s}| {:.20s} | {:.20s}\n'.format(*self.header)
output += '{:.13s}+-{:.20s}--+--{:.20s}\n'.format(*['-'*30]*3)
for mode, modename in self.names.items():
......
......@@ -9,6 +9,8 @@ import dns.name
import dns.rdatatype
import dns.resolver
import ipaddress
def yield_ns_name(nsnames, mapping):
"""
returns: stream of NS names
......@@ -27,14 +29,15 @@ def resolve(qname: dns.name.Name, qtype) -> Set[str]:
#logging.exception(ex)
raise
else:
return set(ip.address for ip in answer)
return set(ipaddress.ip_address(ip.address).compressed for ip in answer)
def get_ips(nsname: dns.name.Name) -> Tuple[dns.name.Name, Set[str]]:
ips = set() # type: Set[str]
try:
ips = resolve(nsname, dns.rdatatype.A)
ips = ips.union(resolve(nsname, dns.rdatatype.AAAA))
except Exception: # return empty address set
except Exception as e: # return empty address set
print(e)
pass
return nsname, ips
......@@ -44,7 +47,7 @@ def load_nsnames() -> Set[dns.name.Name]:
nslist = pickle.load(nslist_file)
logging.info('loaded %s NS names', len(nslist))
return nslist
def load_nsname2ipset() -> Dict[dns.name.Name, Set[str]]:
logging.info('loading previous mapping')
try:
......@@ -93,3 +96,4 @@ if __name__ == "__main__":
print(len(mapping))
# machine readable output: total # of NS names
print(len(nsnames))
\ No newline at end of file
......@@ -9,6 +9,7 @@ import sys
from typing import Dict, List, Iterable, Set, Tuple
import dns.zone
import ipaddress
import dataapi
......@@ -44,7 +45,7 @@ def glue_ns2ipset(nslist: Set[dns.name.Name], zoneobj: dns.zone.Zone) \
for rdtype in (dns.rdatatype.A, dns.rdatatype.AAAA):
rrset = node.get_rdataset(dns.rdataclass.IN, rdtype)
if rrset:
ipset = ipset.union(set(ip.address for ip in rrset))
ipset = ipset.union(set(ipaddress.ip_address(ip.address).compressed for ip in rrset))
if ipset: # do not store glueless names
ns2ipset[nsname] = ipset
return ns2ipset
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment