File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ def response(self, resolution):
59
59
60
60
class DNSServer (object ):
61
61
def __init__ (self ):
62
+ self ._check_localhost ()
62
63
self ._requests = []
63
64
self ._lock = threading .Lock ()
64
65
self ._socket = socket .socket (socket .AF_INET , socket .SOCK_DGRAM )
@@ -67,6 +68,19 @@ def __init__(self):
67
68
self ._running = False
68
69
self ._initialized = False
69
70
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
+
70
84
def pop (self , prefix = None , suffix = None ):
71
85
"""
72
86
Returns received DNS resolution request (if any) that has given
You can’t perform that action at this time.
0 commit comments