whois/whois.py
changeset 64 2ed54e885571
parent 62 fc06c601b875
child 65 50b5966b5566
equal deleted inserted replaced
63:56499470d942 64:2ed54e885571
    88                 if buf.find(nichost) != -1:
    88                 if buf.find(nichost) != -1:
    89                     nhost = nichost
    89                     nhost = nichost
    90                     break
    90                     break
    91         return nhost
    91         return nhost
    92 
    92 
    93     def whois(self, query, hostname, flags):
    93     def whois(self, query, hostname, flags, many_results=False):
    94         """Perform initial lookup with TLD whois server
    94         """Perform initial lookup with TLD whois server
    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         """
   105             if type(query) is not unicode:
   105             if type(query) is not unicode:
   106                 query = query.decode('utf-8')
   106                 query = query.decode('utf-8')
   107 
   107 
   108             if hostname == NICClient.DENICHOST:
   108             if hostname == NICClient.DENICHOST:
   109                 queryBytes = "-T dn,ace -C UTF-8 " + query
   109                 queryBytes = "-T dn,ace -C UTF-8 " + query
   110             elif hostname.endswith(NICClient.QNICHOST_TAIL):
   110             elif hostname.endswith(NICClient.QNICHOST_TAIL) and many_results:
   111                 queryBytes = '=' + query
   111                 queryBytes = '=' + query
   112             else:
   112             else:
   113                 queryBytes = query
   113                 queryBytes = query
   114             s.send((queryBytes + "\r\n").encode('idna'))
   114             s.send((queryBytes + "\r\n").encode('idna'))
   115             # recv returns bytes
   115             # recv returns bytes
   119                 response += d
   119                 response += d
   120                 if not d:
   120                 if not d:
   121                     break
   121                     break
   122             s.close()
   122             s.close()
   123         except socket.error as socketerror:
   123         except socket.error as socketerror:
   124             print 'Error: ', socketerror
   124             print 'Socket Error:', socketerror
   125         nhost = None
   125         nhost = None
   126         response = enforce_ascii(response)
   126         response = enforce_ascii(response)
       
   127         if 'with "=xxx"' in response:
       
   128             return self.whois(query, hostname, flags, True)
   127         if flags & NICClient.WHOIS_RECURSE and nhost is None:
   129         if flags & NICClient.WHOIS_RECURSE and nhost is None:
   128             nhost = self.findwhois_server(response.decode(), hostname, query)
   130             nhost = self.findwhois_server(response.decode(), hostname, query)
   129         if nhost is not None:
   131         if nhost is not None:
   130             response += self.whois(query, nhost, 0)
   132             response += self.whois(query, nhost, 0)
   131         return response.decode()
   133         return response.decode()