# Fetch the extracted network and ASN
network, autnum = m.groups()
+ # Skip the line if there is no network
+ if not network:
+ continue
+
# Decode into strings
- if network:
- network = network.decode()
- if autnum:
- autnum = autnum.decode()
+ network = network.decode()
+
+ # Parse as network object
+ network = ipaddress.ip_network(network)
+
+ # Skip announcements that are too large
+ if isinstance(network, ipaddress.IPv6Network):
+ if network.prefixlen < 10:
+ log.warning("Skipping unusually large network %s" % network)
+ continue
+ elif isinstance(network, ipaddress.IPv4Network):
+ if network.prefixlen < 4:
+ log.warning("Skipping unusually large network %s" % network)
+ continue
# Collect all aggregated networks
if not autnum:
aggregated_networks.append(network)
continue
+ # Decode ASN
+ autnum = autnum.decode()
+
# Insert it into the database
self.db.execute("INSERT INTO announcements(network, autnum) \
VALUES(%s, %s) ON CONFLICT (network) DO \
UPDATE SET autnum = excluded.autnum, last_seen_at = CURRENT_TIMESTAMP",
- network, autnum,
+ "%s" % network, autnum,
)
# Process any aggregated networks