/
client.py
30 lines (26 loc) · 897 Bytes
/
client.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
# -*- coding: utf-8 -*-
from dns import query
from dns import resolver
import subprocess
class DNSClient(object):
def set_address(self, host, port=53, type="tcp"):
self.host = host
self.port = port
self.type = type
def query(self, message, verify=True):
try:
if self.type == "tcp":
response = query.tcp(message, self.host, port=self.port)
elif self.type == "udp":
response = query.udp(message, self.host, port=self.port)
if self.verify(message):
return response
except:
return None
def verify(self, message):
for a in message.answer:
for rdata in a:
address = rdata.to_text()
if subprocess.call(["ping", "-c 1", address], shell=True) != 0:
return False
return True