95 then, if the quick flag is false, search that result |
95 then, if the quick flag is false, search that result |
96 for the region-specifc whois server and do a lookup |
96 for the region-specifc whois server and do a lookup |
97 there for contact details |
97 there for contact details |
98 """ |
98 """ |
99 response = b'' |
99 response = b'' |
|
100 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
101 s.settimeout(10) |
|
102 s.connect((hostname, 43)) |
|
103 |
100 try: |
104 try: |
101 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
105 query = query.decode('utf-8') |
102 s.settimeout(10) |
106 except UnicodeEncodeError: |
103 s.connect((hostname, 43)) |
107 pass # Already Unicode (python2's error) |
104 |
108 except AttributeError: |
105 try: |
109 pass # Already Unicode (python3's error) |
106 query = query.decode('utf-8') |
110 |
107 except UnicodeEncodeError: |
111 if hostname == NICClient.DENICHOST: |
108 pass # Already Unicode (python2's error) |
112 query_bytes = "-T dn,ace -C UTF-8 " + query |
109 except AttributeError: |
113 elif hostname.endswith(NICClient.QNICHOST_TAIL) and many_results: |
110 pass # Already Unicode (python3's error) |
114 query_bytes = '=' + query |
111 |
115 else: |
112 if hostname == NICClient.DENICHOST: |
116 query_bytes = query |
113 query_bytes = "-T dn,ace -C UTF-8 " + query |
117 s.send(bytes(query_bytes,'utf-8') + b"\r\n") |
114 elif hostname.endswith(NICClient.QNICHOST_TAIL) and many_results: |
118 # recv returns bytes |
115 query_bytes = '=' + query |
119 while True: |
116 else: |
120 d = s.recv(4096) |
117 query_bytes = query |
121 response += d |
118 s.send(bytes(query_bytes,'utf-8') + b"\r\n") |
122 if not d: |
119 # recv returns bytes |
123 break |
120 while True: |
124 s.close() |
121 d = s.recv(4096) |
|
122 response += d |
|
123 if not d: |
|
124 break |
|
125 s.close() |
|
126 except socket.error as socketerror: |
|
127 print('Socket Error:', socketerror) |
|
128 |
125 |
129 nhost = None |
126 nhost = None |
130 response = response.decode('utf-8', 'replace') |
127 response = response.decode('utf-8', 'replace') |
131 if 'with "=xxx"' in response: |
128 if 'with "=xxx"' in response: |
132 return self.whois(query, hostname, flags, True) |
129 return self.whois(query, hostname, flags, True) |