-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_soa.py
35 lines (26 loc) · 1.08 KB
/
get_soa.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import subprocess
import logging
log = logging.getLogger(__name__)
def format_output(output: str) -> tuple:
output = output.split(" ")
server = output[0].strip(".")
contact = output[1].strip(".")
return (server, contact)
def get_SOA(domain: str) -> tuple:
output = None
try:
output = subprocess.check_output(['dig',"soa",domain, '+short'])
output = str(output, 'utf-8').replace("\n",",").strip(",")
if 'NXDOMAIN' in output:
log.error(domain + ",unexpected NX domain error when getting SOA record\n")
elif(output == ""):
output = subprocess.check_output(['dig', "soa", "www." + domain, '+short'])
output = str(output, 'utf-8').replace("\n",",").strip(",")
return format_output(output)
elif 'SERVFAIL' in output:
log.error(domain + ",unexpected SERVFAIL error when getting SOA record\n")
else:
return format_output(output)
except subprocess.CalledProcessError as e:
log.exception(domain + "," + str(e.output) + "\n")
return output