2022-08-26 13:02:52 +03:00
|
|
|
import subprocess
|
2022-09-15 17:54:30 +03:00
|
|
|
from utils import prettyprint
|
2022-08-26 13:02:52 +03:00
|
|
|
|
|
|
|
def resolve_by_spf(domain):
|
|
|
|
output = subprocess.run(["nslookup", "-q=TXT", domain], capture_output=True)
|
|
|
|
lines = output.stdout.decode().split('\n')
|
|
|
|
|
|
|
|
result = []
|
|
|
|
|
|
|
|
for line in lines:
|
|
|
|
res = line.find('v=spf')
|
|
|
|
|
|
|
|
if res == -1:
|
|
|
|
continue
|
|
|
|
|
|
|
|
values = line[res:].split()
|
|
|
|
|
|
|
|
for val in values:
|
|
|
|
if val.startswith("include:"):
|
|
|
|
result += resolve_by_spf(val[8:].strip())
|
|
|
|
|
|
|
|
if val.startswith("ip4:"):
|
|
|
|
result.append(val[4:].strip())
|
|
|
|
|
|
|
|
return list(dict.fromkeys(result))
|
|
|
|
|
2022-09-15 17:54:30 +03:00
|
|
|
def main():
|
|
|
|
ips = resolve_by_spf("_spf.google.com")
|
2022-08-26 13:02:52 +03:00
|
|
|
|
2022-09-15 17:54:30 +03:00
|
|
|
with open('ips.txt', 'a') as out:
|
|
|
|
for ip in ips:
|
|
|
|
out.write(prettyprint(ip, 'google (spf)') + '\n')
|