From f2609c72d887785a36174a8d99c1e8c143f46acf Mon Sep 17 00:00:00 2001 From: James Bensley Date: Sun, 17 Nov 2024 13:12:12 +0100 Subject: [PATCH] Add prefixes from unregistered ASNs to text report --- dnas/dnas/report.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/dnas/dnas/report.py b/dnas/dnas/report.py index 61e5dfb..47a3cad 100644 --- a/dnas/dnas/report.py +++ b/dnas/dnas/report.py @@ -473,6 +473,33 @@ def gen_txt_report(mrt_s: "mrt_stats", body: bool = True) -> list[str]: txt_report.append(text) + if mrt_s.most_unreg_origins: + text = ( + f"Prefixes with most unregistered origin ASNs per prefix: " + f"{len(mrt_s.most_unreg_origins)} prefix(es) had " + f"{len(mrt_s.most_unreg_origins[0].origin_asns)} bogon origin ASNs.\n" + ) + + txt_report.append(text) + + if body: + text = "" + for mrt_e in mrt_s.most_unreg_origins: + text += f"Prefix {mrt_e.prefix} from origin ASN(s)" + for asn in mrt_e.origin_asns: + if asn not in whois_cache: + whois_cache[asn] = whois.as_lookup(int(asn)) + as_name = whois_cache[asn] + if as_name: + text += f" AS{asn} ({as_name})" + else: + text += f" AS{asn}" + text += "\n" + text = text[0:-1] + text += "\n\n" + + txt_report.append(text) + return txt_report @staticmethod