добавляет google_ranges

This commit is contained in:
2022-09-16 18:05:39 +03:00
parent f6d19ba5b4
commit 4faeaaa7f0
9 changed files with 85 additions and 32 deletions

View File

@@ -5,17 +5,18 @@ from utils import prettyprint
ips = []
dict = defaultdict(list)
def main():
with open('ips.txt', 'w') as out:
for line in open('domains.txt'):
l = line.strip()
def main(file_data: list):
for line in open('domains.txt'):
l = line.strip()
if l.startswith('#') or l == '':
continue
if l.startswith('#') or l == '':
continue
dict[socket.gethostbyname(l) + '/32'].append(l)
dict[socket.gethostbyname(l) + '/32'].append(l)
ips = list(dict.keys())
ips = list(dict.keys())
for ip in ips:
out.write(prettyprint(ip, ', '.join(dict[ip])) + '\n')
for ip in ips:
file_data.append(prettyprint(ip, ', '.join(dict[ip])) + '\n')
return file_data

View File

@@ -24,9 +24,11 @@ def resolve_by_spf(domain):
return list(dict.fromkeys(result))
def main():
def main(file_data: list):
ips = resolve_by_spf("_spf.google.com")
with open('ips.txt', 'a') as out:
for ip in ips:
out.write(prettyprint(ip, 'google (spf)') + '\n')
for ip in ips:
file_data.append(prettyprint(ip, 'google (spf)') + '\n')
return file_data

View File

@@ -0,0 +1,34 @@
from collections import defaultdict
from utils import prettyprint
import ipaddress
new_ips_data = defaultdict(list)
cloud_ranges_file = open("google_ranges.txt", "r")
cloud_ranges = [x.strip() for x in cloud_ranges_file.readlines()]
def process_list(item: str):
l = item.strip()
if l.startswith('#') or l == '':
return True
[range, comment] = [x.strip() for x in l.split('#')]
for cloud_range in cloud_ranges:
if ipaddress.ip_network(range).subnet_of(ipaddress.ip_network(cloud_range)):
new_ips_data[cloud_range].append(f'{comment} ({range})')
return False
return True
def main(file_data: list[str]):
file_data = list(filter(process_list, file_data))
ips = list(new_ips_data.keys())
for ip in ips:
file_data.append(prettyprint(ip, 'google_range :: ' + ', '.join(new_ips_data[ip])) + '\n')
return file_data

View File

@@ -1,7 +1,5 @@
def main():
inp = open('ips.txt', 'r')
uniqlines = list(dict.fromkeys(inp.readlines()))
inp.close()
def main(file_data: list[str]):
uniqlines = list(dict.fromkeys(file_data))
out = open('ips.txt', 'w')
out.writelines(uniqlines)
out.truncate(out.tell()-1)