whois/whois.py
changeset 52 1f80f6dec7ac
parent 45 52ce01013731
child 60 7801a420f679
equal deleted inserted replaced
51:1459aa5d7ce4 52:1f80f6dec7ac
   120         there for contact details
   120         there for contact details
   121         """
   121         """
   122         # print 'Performing the whois'
   122         # print 'Performing the whois'
   123         # print 'parameters given:', query, hostname, flags
   123         # print 'parameters given:', query, hostname, flags
   124         # pdb.set_trace()
   124         # pdb.set_trace()
   125         s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
   125         try:
   126         s.connect((hostname, 43))
   126           s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
   127         """send takes bytes as an input
   127           s.settimeout(2)
   128         """
   128           s.connect((hostname, 43))
   129         queryBytes = None
   129           """send takes bytes as an input
   130         if type(query) is not unicode:
   130           """
   131             query = query.decode('utf-8')
   131           queryBytes = None
   132 
   132           if type(query) is not unicode:
   133         if (hostname == NICClient.DENICHOST):
   133               query = query.decode('utf-8')
   134             # print 'the domain is in NIC DENIC'
   134 
   135             queryBytes = ("-T dn,ace -C UTF-8 " + query + "\r\n").encode('idna')
   135           if (hostname == NICClient.DENICHOST):
   136             # print 'queryBytes:', queryBytes
   136               # print 'the domain is in NIC DENIC'
   137         else:
   137               queryBytes = ("-T dn,ace -C UTF-8 " + query + "\r\n").encode('idna')
   138             queryBytes = (query + "\r\n").encode('idna')
   138               # print 'queryBytes:', queryBytes
   139         s.send(queryBytes)
   139           else:
   140         """recv returns bytes
   140               queryBytes = (query + "\r\n").encode('idna')
   141         """
   141           s.send(queryBytes)
   142         # print s
   142           """recv returns bytes
   143         response = b''
   143           """
   144         while True:
   144           # print s
   145             d = s.recv(4096)
   145           response = b''
   146             response += d
   146           while True:
   147             if not d:
   147               d = s.recv(4096)
   148                 break
   148               response += d
   149         s.close()
   149               if not d:
       
   150                   break
       
   151           s.close()
       
   152         except socket.error as socketerror:
       
   153           print("Error: ", socketerror)
   150         # pdb.set_trace()
   154         # pdb.set_trace()
   151         nhost = None
   155         nhost = None
   152         # print 'response', response
   156         # print 'response', response
   153         response = enforce_ascii(response)
   157         response = enforce_ascii(response)
   154         if (flags & NICClient.WHOIS_RECURSE and nhost is None):
   158         if (flags & NICClient.WHOIS_RECURSE and nhost is None):