2022-09-18 09:14:58 +03:00
|
|
|
import ipaddress
|
2022-09-15 17:54:30 +03:00
|
|
|
import socket
|
|
|
|
from collections import defaultdict
|
|
|
|
from utils import prettyprint
|
|
|
|
|
|
|
|
ips = []
|
|
|
|
dict = defaultdict(list)
|
|
|
|
|
2022-09-16 18:15:04 +03:00
|
|
|
def main(file_data: list):
|
|
|
|
for line in open('domains.txt'):
|
|
|
|
l = line.strip()
|
2022-09-15 17:54:30 +03:00
|
|
|
|
2022-09-16 18:15:04 +03:00
|
|
|
if l.startswith('#') or l == '':
|
|
|
|
continue
|
2022-09-15 17:54:30 +03:00
|
|
|
|
2022-09-18 09:14:58 +03:00
|
|
|
domain_or_range, comment, *_ = [x.strip() for x in l.split('#')] + [None]
|
|
|
|
|
|
|
|
try:
|
|
|
|
ipaddress.ip_network(domain_or_range)
|
|
|
|
dict[domain_or_range].append(comment)
|
|
|
|
|
|
|
|
except ValueError:
|
2022-09-18 09:23:02 +03:00
|
|
|
|
|
|
|
hostname_data = socket.gethostbyname_ex(domain_or_range)
|
|
|
|
for ip in hostname_data[2]:
|
|
|
|
dict[ip + '/32'].append(l)
|
2022-09-15 17:54:30 +03:00
|
|
|
|
2022-09-16 18:15:04 +03:00
|
|
|
ips = list(dict.keys())
|
2022-09-15 17:54:30 +03:00
|
|
|
|
2022-09-16 18:15:04 +03:00
|
|
|
for ip in ips:
|
|
|
|
file_data.append(prettyprint(ip, ', '.join(dict[ip])) + '\n')
|
|
|
|
|
|
|
|
return file_data
|