【问题标题】:Establish a connection through socks with socket library通过socks与socket库建立连接
【发布时间】:2016-07-27 10:37:52
【问题描述】:

我有这个脚本,它只使用袜子列表并尝试连接到主机。但它总是显示这个错误:

  File "*.py", line 38, in requestsocks
    s.connect((host, port))
  File "/home/*/.local/lib/python3.5/site-packages/socks.py", line 729, in connect
    _BaseSocket.connect(self, proxy_addr)
TypeError: an integer is required (got type str)

代码如下:

import socket,socks,random

def checkurl():
    global url
    global url2
    global urlport
    url = input("Insert URL: ")
    if url[0]+url[1]+url[2]+url[3] == "www.":
        url = "http://" + url
    elif url[0]+url[1]+url[2]+url[3] == "http":
        pass
    else:
        url = "http://" + url

    try:
        url2 = url.replace("http://", "").replace("https://", "").split('/')[0].split(":")[0]
    except:
        url2 = url.replace("http://", "").replace("https://", "").split('/')[0]

    try:
        urlport = url.replace("http://", "").replace("https://", "").split('/')[0].split(':')[1]
    except:
        urlport = "80"

def proxylist():
    global entries
    out_file = str(input("Enter the proxy list: "))
    entries = open(out_file).readlines()
    requestsocks()

def requestsocks(): 
    while True:
        proxy = random.choice(entries).strip().split(':')
        host = str(url2)
        port = int(urlport)
        socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, proxy[0], proxy[1], True)
        s = socks.socksocket()
        s.connect((host, port))
        s.sendall('Hello world')

checkurl()
proxylist()

我不知道我该如何解决这个问题。想法? 附:我从这里拿了袜子清单:https://www.socks-proxy.net/

【问题讨论】:

    标签: sockets python-3.x socks


    【解决方案1】:

    我对套接字库做的不多,但它要求主机和端口都输入一个整数。尝试像这样获取 IP。

    添加这个 ------> host = socket.gethostbyname(host)

    def requestsocks(): 
        while True:
            proxy = random.choice(entries).strip().split(':')
            host = str(url2)
            # convert url to IP address
            host = socket.gethostbyname(host)
            port = int(urlport)
            socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, proxy[0], proxy[1], True)
            s = socks.socksocket()
            s.connect((host, port))
            s.sendall('Hello world')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-14
      • 2018-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多