File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ def response(self, resolution):
5959
6060class 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
You can’t perform that action at this time.
0 commit comments