whois/whois.py
changeset 177 7030835bcf5e
parent 163 faaa3ce1af3e
child 178 06e9b88e0c20
equal deleted inserted replaced
176:1bd3f3f7fe2a 177:7030835bcf5e
    36 from builtins import object
    36 from builtins import object
    37 import re
    37 import re
    38 import sys
    38 import sys
    39 import socket
    39 import socket
    40 import optparse
    40 import optparse
    41 
    41 import os
    42 
    42 
    43 class NICClient(object):
    43 class NICClient(object):
    44 
    44 
    45     ABUSEHOST = "whois.abuse.net"
    45     ABUSEHOST = "whois.abuse.net"
    46     NICHOST = "whois.crsnic.net"
    46     NICHOST = "whois.crsnic.net"
    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)
   100         if "SOCKS" in os.environ:
       
   101              try:
       
   102                   import socks
       
   103              except Exception as e:
       
   104                   print(str(e))
       
   105                   print("You need to install the Python socks module.  Install PIP (https://bootstrap.pypa.io/get-pip.py).  Then 'pip install PySocks' ")
       
   106                   sys.exit(0)
       
   107              socksproxy,port = os.environ["SOCKS"].split(":")
       
   108              s = socks.socksocket()
       
   109              s.set_proxy(socks.SOCKS5, socksproxy, int(port))
       
   110         else:
       
   111              s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
   101         s.settimeout(10)
   112         s.settimeout(10)
   102         s.connect((hostname, 43))
   113         s.connect((hostname, 43))
   103 
   114 
   104         try:
   115         try:
   105             query = query.decode('utf-8')
   116             query = query.decode('utf-8')