-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdns_score.py
24 lines (21 loc) · 881 Bytes
/
dns_score.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
import dns.message, dns.query
from time import sleep
DPORT = 53 # UDP
def score_DNS(queue, alive, lock, target, value, target_port=DPORT):
query = dns.message.make_query(".", dns.rdatatype.NS, flags=0) # Create a query to
while alive():
try:
res = dns.query.udp(query, target, timeout=10)
if res.answer is not None:
lock.acquire()
queue.put({'service': 'dns', 'status': 'UP', 'host' : target, 'value':value})
lock.release()
else:
lock.acquire()
queue.put({'service': 'dns', 'status': 'DOWN', 'host' : target, 'value':value})
lock.release()
except Exception:
lock.acquire()
queue.put({'service': 'dns', 'status': 'DOWN', 'host' : target, 'value':value})
lock.release()
sleep(60)