nDPI/utils/mergeipaddrlist.py
Ivan Nardi 8b062295cc
Add some scripts to easily update some IPs lists (#1449)
While the lists in a6ff0dd0 and 2f5f445f are somehow provided by the
companies themselves (or by some interested parties), these new lists
are directly extracted from BGP information, via AS prefixes.

*Usually*, these new lists are far more stable than the previous ones.

TODO:
* add some other ASNs (see `src/lib/ndpi_content_match.c.inc`)
* IPv6, as usual :-(
2022-02-25 14:26:26 +01:00

20 lines
389 B
Python
Executable file

#!/usr/bin/env python3
import sys
import socket
import struct
import netaddr
if len (sys.argv) == 3:
proto = sys.argv[2]
if len(sys.argv) < 2:
print("Usage: mergeipaddrlist.py <file>")
sys.exit (1)
ipFile = open(sys.argv[1])
ipAddresses = list(ipFile.readlines())
ipAddresses = sorted(ipAddresses)
cidrs = netaddr.cidr_merge(ipAddresses)
for cidr in cidrs:
print(cidr)