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


Python socks.socksocket函数代码示例

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


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

示例1: start

    def start(self):
        self.server = self.config['server']
        self.port = int(self.config['port'])
        if self.config['proxyhost'] is None:
            if self.config['ssl'] is True:
                if self.ipv6:
                    self.sock = wrap_socket(socket.socket(socket.AF_INET6, socket.SOCK_STREAM))
                else:
                    self.sock = wrap_socket(socket.socket(socket.AF_INET, socket.SOCK_STREAM))
            else:
                if self.ipv6:
                    self.sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
                else:
                    self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        else:
            if self.config['ssl'] is True:
                temp_socket = socks.socksocket()
                temp_socket.setproxy(socks.PROXY_TYPE_SOCKS4, self.config['proxyhost'], self.config['proxyport'], True)
                self.sock = wrap_socket(temp_socket)
            else:
                self.sock = socks.socksocket()
                self.sock.setproxy(socks.PROXY_TYPE_SOCKS4, self.config['proxyhost'], self.config['proxyport'], True)
        self.sock.connect((self.server, self.port))

        #send pass
        if self.config["pass"] is not None:
            self.send("PASS " + self.config["pass"], True)

        self.send("USER " + self.user + " 127.0.0.1 " + self.server + " :" + self.real, True)
        self.set_nick(self.nick)
        self.main()
开发者ID:ldionmarcil,项目名称:ircsnapshot,代码行数:31,代码来源:ircsnapshot.py

示例2: test_mock_connect

def test_mock_connect():
  m = mox.Mox()

  class MockSocket(object):
    def setproxy(self, *args):
      self.args = args
    def settimeout(self, value):
      self.timeout = value
    def connect(self, tup):
      self.host, self.port = tup

  mock_socket = MockSocket()

  m.StubOutWithMock(socks, 'socksocket')
  socks.socksocket().AndReturn(mock_socket)
  m.ReplayAll()

  handler = make_handler('foo', 1234)
  conn = handler.build_connection('www.google.com', timeout=1)
  conn.connect()
  assert mock_socket.args == conn._proxyargs
  assert mock_socket.timeout == 1
  assert mock_socket.host == 'www.google.com'
  assert mock_socket.port == 80

  m.UnsetStubs()
  m.VerifyAll()
开发者ID:jayeye,项目名称:commons,代码行数:27,代码来源:test_socks.py

示例3: connect_to_channel

def connect_to_channel(hostname, port, party):
    mylog('Trying to connect to %s for party %d' % (repr((hostname, port)), party), verboseLevel=-1)
    retry = True
    s = socks.socksocket()
    while retry:
      try:
        s = socks.socksocket()
        s.connect((hostname, port))
        retry = False
      except Exception, e:  # socks.SOCKS5Error:
        retry = True
        gevent.sleep(1)
        s.close()
        mylog('retrying (%s, %d) caused by %s...' % (hostname, port, str(e)) , verboseLevel=-1)
开发者ID:amiller,项目名称:HoneyBadgerBFT,代码行数:14,代码来源:honest_party_test_EC2.py

示例4: connect_to_channel

def connect_to_channel(hostname, port, party):
    mylog('Trying to connect to %s for party %d' % (repr((hostname, port)), party), verboseLevel=-2)
    retry = True
    s = socks.socksocket()
    while retry:
      try:
        s = socks.socksocket()
        s.setproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", TOR_SOCKSPORT[party], True)
        s.connect((hostname, port))
        retry = False
      except Exception, e:  # socks.SOCKS5Error:  # still no idea why socks over tor would always generate this error
        retry = True
        gevent.sleep(1)
        s.close()
        mylog('retrying (%s, %d) caused by %s...' % (hostname, port, str(e)) , verboseLevel=-2)
开发者ID:amiller,项目名称:HoneyBadgerBFT,代码行数:15,代码来源:honest_party_test_tor_multipleCircuits.py

示例5: ensure_connected

	def ensure_connected(self, connection, proto, host, timeout):
		if connection != None and connection.sock != None:
			return connection, False

		if proto == 'https': connector = httplib.HTTPSConnection
		else: connector = httplib.HTTPConnection

		if not self.config.proxy:
			return connector(host, strict=True, timeout=timeout), True

		host, port = host.split(':')

		proxy_proto, user, pwd, proxy_host, name = self.config.proxy
		proxy_port = 1050
		proxy_host = proxy_host.split(':')
		if len(proxy_host) > 1:
			proxy_port = int(proxy_host[1]); proxy_host = proxy_host[0]

		connection = connector(host, strict=True)
		connection.sock = socks.socksocket()
		#connection.sock.settimeout(timeout)

		proxy_type = socks.PROXY_TYPE_SOCKS5
		if proxy_proto == 'http':
			proxy_type = socks.PROXY_TYPE_HTTP
		elif proxy_proto == 'socks4':
			proxy_type = socks.PROXY_TYPE_SOCKS4

		connection.sock.setproxy(proxy_type, proxy_host, proxy_port, True, user, pwd)
		try:
			connection.sock.connect((host, int(port)))
		except socks.Socks5AuthError as e:
			self.miner.stop('Proxy error: ' + str(e))
		return connection, True
开发者ID:cnasty,项目名称:poclbm,代码行数:34,代码来源:HttpTransport.py

示例6: socket_SOCKS5_IP_test

def socket_SOCKS5_IP_test():
    s = socks.socksocket()
    s.set_proxy(socks.SOCKS5, "127.0.0.1", 1081)
    s.connect(("95.211.60.37", 80))
    s.sendall(raw_HTTP_request())
    status = s.recv(2048).splitlines()[0]
    assert status.startswith(b"HTTP/1.1 200")
开发者ID:ifeco2,项目名称:PySocks,代码行数:7,代码来源:sockstest.py

示例7: run

    def run(self):
        while self.running:
            while self.running:
                try:
                    if self.tor:
                        self.socks.setproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 9050)
                    self.socks.connect((self.host, self.port))
                    print term.BOL + term.UP + term.CLEAR_EOL + "T0r b0ts c0nnected" + term.NORMAL
                    break
                except Exception, e:
                    if e.args[0] == 106 or e.args[0] == 60:
                        break
                    print term.BOL + term.UP + term.CLEAR_EOL + "Error connecting" + term.NORMAL
                    time.sleep = (random.uniform(1, 3))
                    continue

            while self.running:
                try:
                    random.choice[(self._send_http_post(), self._send_http_get())]
                except Exception, e:
                    if e.args[0] == 32 or e.args[0] == 104:
                        print term.BOL + term.UP + term.CLEAR_EOL + "Broken threads, restarting..." + term.NORMAL
                        self.socks = socks.socksocket()
                        break
                    time.sleep(0.1)
                    pass
开发者ID:m4s0,项目名称:torshammer666,代码行数:26,代码来源:torshammer666.py

示例8: init_tcp

    def init_tcp(self, host, port, proxy=None, use_ssl=True):
        self.init_server(host, port, proxy, use_ssl)

        global proxy_modes
        self.connection_msg = "%s:%d"%(self.host,self.port)
        if self.proxy is None:
            s = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
        else:
            self.connection_msg += " using proxy %s:%s:%s"%(self.proxy.get('mode'), self.proxy.get('host'), self.proxy.get('port'))
            import socks
            s = socks.socksocket()
            s.setproxy(proxy_modes.index(self.proxy["mode"]) + 1, self.proxy["host"], int(self.proxy["port"]) )

        if self.use_ssl:
            s = ssl.wrap_socket(s, ssl_version=ssl.PROTOCOL_SSLv23)
            
        s.settimeout(2)
        s.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)

        try:
            s.connect(( self.host.encode('ascii'), int(self.port)))
            s.settimeout(60)
            self.s = s
            self.is_connected = True
        except:
            self.is_connected = False
            self.s = None
开发者ID:taiping194,项目名称:electrum,代码行数:27,代码来源:interface.py

示例9: connect

    def connect(self):
        if self.host.endswith('.onion'):
            event = Event(IRC_EVENT,"Using Tor")
            getEventManager().signalEvent(event)
            import socks
            self.socket.settimeout(30)
            self.socket = socks.socksocket(_sock=self.socket)
            self.socket.setproxy(proxytype=socks.PROXY_TYPE_SOCKS5,addr='127.0.0.1',port=9050)
        event = Event(IRC_EVENT,"Connecting...")
        getEventManager().signalEvent(event)
        self.listenThread = ListenThread(self.socket, self)

        try:
            self.socket.connect((self.host, self.port))
        except Exception as e:
            event = EVent(IRC_EVENT, "Connection Failure, "+str(e) )
            getEVentManager().signalEvent(event)
            return
        
        if self.online_hook:
            self.online_hook()

        self.connected = True

        self.listenThread.start()
        self.socket.send("NICK %s\r\n" % self.nick)
        self.socket.send("USER IRCLOIC %s blah :Newfag's remote LOIC\r\n" % self.host)
开发者ID:amisan,项目名称:LOIC_Python_Staging,代码行数:27,代码来源:IRC.py

示例10: connect

 def connect(self):
     sock = socks.socksocket()
     sock.setproxy(*self.proxyargs)
     if type(self.timeout) in (int, float):
         sock.settimeout(self.timeout)
     sock.connect((self.host, self.port))
     self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file)
开发者ID:MtimerCMS,项目名称:SublimeText-Google-Translate-Plugin,代码行数:7,代码来源:testtranslate.py

示例11: atest

def atest(x,a):
	while True:
		try:
			x = proxies.pop(0)
		except:
			sys.stderr.write("- Finished")
			return
		state = ""
		test = ["HTTP", "SOCKS4", "SOCKS5"]
		for mode in test:
			kmode = eval("socks.PROXY_TYPE_" + mode)
			try:
				s = socks.socksocket()
				s.settimeout(5)
				s.setproxy(kmode, x.split(":")[0], int(x.split(":")[1].replace("\n","")))
				s.connect(("www.ubuntu.com",80))
				s.sendall("GET / HTTP/1.1\r\nHost: www.ubuntu.com\r\n\r\n")
				kddt = s.recv(500)
				if kddt.find("Home | Ubuntu"):
					state = mode
					s.close()
					break
				s.close()
			except:
				pass
		if state != "":
			syncprint(state + "|" + x.replace("\n",""))
开发者ID:Arm4x,项目名称:Quartz,代码行数:27,代码来源:ProxyPurifier.py

示例12: clientConnectionThread

def clientConnectionThread(stdscr,ServerOnionURL,msgs):
	global roster
	# Try to load Socksipy
	try:
		import socks
	except:
		print "[E] Can't load socksiphy module."
		print "[E] Try installing python-socksipy in debian-like distros"
		exit(0)
	while(True):
		try: 
			log("Trying to connect to %s:%d" % (ServerOnionURL,hidden_service_port))
			## Connects to TOR via Socks
			s=socks.socksocket(socket.AF_INET,socket.SOCK_STREAM)
			s.setproxy(socks.PROXY_TYPE_SOCKS5,tor_server,tor_server_socks_port)
			s.settimeout(100)
			s.connect((ServerOnionURL,hidden_service_port))
			s.setblocking(0)
			log("clientConnection: Connected to %s" % ServerOnionURL)
			log("clientConnection: Autorequesting roster...")
			msgs.append("/roster")
			randomwait=random.randint(1,clientRandomWait)
		except:
			log("clientConnection: Can't connect! retrying...")
			time.sleep(1)
			continue
		try:
			while(True):
				time.sleep(1)
				ready = select.select([s], [], [], 1.0)
				# received data from server
				if ready[0]:
					data=sanitize(s.recv(minimum_message_len))
					# received pong (ignore)
					if data.find("/PING ")>-1:
						continue 
					# received roster list
					if data.startswith("--roster"):
						roster=[]
						for i in data.split(' ')[1:]:
							roster.append(i)
					# Write received data to channel
					log(data)
				# We need to send a message
				if len(msgs)>0:  
					randomwait-=1 # Wait some random time to add noise
					if randomwait==0:
						m = addpadding(msgs.pop(0))
						s.sendall(m)
						randomwait=random.randint(1,clientRandomWait)
				# send noise in form of PINGs
				if random.randint(0,clientRandomNoise)==0:
					ping="/PING "
					for i in range(120):
						ping+="%02X" % random.randint(0,255)
					#log("Sending %s" % ping)
					msgs.append(ping)
		except:
			s.close()
			pass
开发者ID:akiraaisha,项目名称:torirc,代码行数:60,代码来源:torirc.py

示例13: run

    def run(self):
        self.rep = REPEAT
        down = False
        while self.rep:
            try:
                if I2P:
                    s = socks.socksocket()
                    s.setproxy(socks.PROXY_TYPE_SOCKS5,"127.0.0.1", 4475)
                else:
                    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                s.connect((HOST, PORT))

                down = False
                s.send('GET / HTTP/1.0\r\n')
                s.send('Host: %s\r\n' % (HOST))
                s.send('User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.503l3; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; MSOffice 12)\r\n')
                s.send('Content-Length: 42\r\n')
                while True:        
                    sleep(DELAY)
                    s.send('X-a: b\r\n')
                
                # send this to shut down connections
                # s.send('\r\n')
                # s.close()
            except Exception:
                if not down:
                    print "TANGO DOWN"
                    down = True
开发者ID:melpomene,项目名称:Darkloris,代码行数:28,代码来源:darkloris.py

示例14: put_flag

def put_flag(ip, flag):
	user = id_generator()
	try:
		socket = socks.socksocket()                                                           
		socket.connect((ip , 16404))  
		a = socket.recv(1024)
		socket.send("reg\n")
		a = socket.recv(1024)
		socket.send(user + "\n")
		a = socket.recv(1024)
		b = re.compile('is (.*)\n')
		token = b.findall(a)
		a = socket.recv(1024)
		socket.send("add\n")
		a = socket.recv(1024)
		socket.send(flag + "\n")
		a = socket.recv(1024)
		socket.close()

		if len(token) < 1:
			status["error"].append(4)
			return False

		return token[0]

	except:
		status["error"].append(4)
		return False
开发者ID:Sheld42,项目名称:Repka,代码行数:28,代码来源:checker_perl.py

示例15: check_flag

def check_flag(ip, flag, info):
	try:
		socket = socks.socksocket()                                                           
		socket.connect((ip , 16404))  
		a = socket.recv(1024)
		socket.send("auth\n")
		a = socket.recv(1024)
		socket.send(info + "\n")
		a = socket.recv(1024)

		if "Wrong" in a:
			status["error"].append(4)
			return False

		a = socket.recv(1024)
		socket.send("read\n")
		a = socket.recv(1024)
		if flag in a:
			return True
		else:
			status["error"].append(3)
			return False
	except:
		status["error"].append(4)
		return False
开发者ID:Sheld42,项目名称:Repka,代码行数:25,代码来源:checker_perl.py


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