Added checking of localhost for another DNS service on *:53

This commit is contained in:
Miroslav Stampar 2016-02-03 11:55:13 +01:00
parent 4916f1b2b2
commit b07685a386

View File

@ -59,6 +59,7 @@ class DNSQuery(object):
class DNSServer(object):
def __init__(self):
self._check_localhost()
self._requests = []
self._lock = threading.Lock()
self._socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
@ -67,6 +68,19 @@ class DNSServer(object):
self._running = False
self._initialized = False
def _check_localhost(self):
response = ""
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("", 53))
s.send("6509012000010000000000010377777706676f6f676c6503636f6d00000100010000291000000000000000".decode("hex")) # A www.google.com
response = s.recv(512)
except:
pass
finally:
if response and "google" in response:
raise socket.error("another DNS service already running on *:53")
def pop(self, prefix=None, suffix=None):
"""
Returns received DNS resolution request (if any) that has given