Skip to content

Commit b07685a

Browse files
committed
Added checking of localhost for another DNS service on *:53
1 parent 4916f1b commit b07685a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lib/request/dns.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def response(self, resolution):
5959

6060
class DNSServer(object):
6161
def __init__(self):
62+
self._check_localhost()
6263
self._requests = []
6364
self._lock = threading.Lock()
6465
self._socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
@@ -67,6 +68,19 @@ def __init__(self):
6768
self._running = False
6869
self._initialized = False
6970

71+
def _check_localhost(self):
72+
response = ""
73+
try:
74+
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
75+
s.connect(("", 53))
76+
s.send("6509012000010000000000010377777706676f6f676c6503636f6d00000100010000291000000000000000".decode("hex")) # A www.google.com
77+
response = s.recv(512)
78+
except:
79+
pass
80+
finally:
81+
if response and "google" in response:
82+
raise socket.error("another DNS service already running on *:53")
83+
7084
def pop(self, prefix=None, suffix=None):
7185
"""
7286
Returns received DNS resolution request (if any) that has given

0 commit comments

Comments
 (0)