Maxim Slipenko
b748fb1c96
Co-authored-by: Maxim Slipenko <no-reply@maxim.slipenko.com> Reviewed-on: #1
35 lines
812 B
Python
35 lines
812 B
Python
import subprocess
|
|
from utils import prettyprint
|
|
|
|
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))
|
|
|
|
def main(file_data: list):
|
|
ips = resolve_by_spf("_spf.google.com")
|
|
|
|
for ip in ips:
|
|
file_data.append(prettyprint(ip, 'google (spf)') + '\n')
|
|
|
|
return file_data
|
|
|