diff --git a/lib/request/dns.py b/lib/request/dns.py index 38099ebfa..b619fbdfc 100644 --- a/lib/request/dns.py +++ b/lib/request/dns.py @@ -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