whois/whois.py
changeset 177 7030835bcf5e
parent 163 faaa3ce1af3e
child 178 06e9b88e0c20
--- a/whois/whois.py	Mon Apr 23 18:43:05 2018 +0300
+++ b/whois/whois.py	Tue May 08 08:47:28 2018 -0400
@@ -38,7 +38,7 @@
 import sys
 import socket
 import optparse
-
+import os
 
 class NICClient(object):
 
@@ -97,7 +97,18 @@
         there for contact details
         """
         response = b''
-        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        if "SOCKS" in os.environ:
+             try:
+                  import socks
+             except Exception as e:
+                  print(str(e))
+                  print("You need to install the Python socks module.  Install PIP (https://bootstrap.pypa.io/get-pip.py).  Then 'pip install PySocks' ")
+                  sys.exit(0)
+             socksproxy,port = os.environ["SOCKS"].split(":")
+             s = socks.socksocket()
+             s.set_proxy(socks.SOCKS5, socksproxy, int(port))
+        else:
+             s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         s.settimeout(10)
         s.connect((hostname, 43))