代理可用性批量检测- Python

该绍

  • 可以简单方便的测试出代理是否可用或速度,以及代理类型!
  • 目录结构
.
├── Socks5批量验证.py
├── success.txt
└── target.txt

0 directories, 3 files

运行

  • 需要安装 vthread库
  • target.txt格式(代理目标,支持三种格式):

    socks5://34.92.218.103:20000
    http://34.92.218.103:20000
    https://34.92.218.103:20000

  • 运行代码 python3 sockeVerify.py

  • 扫描后的结果保存在 success.txt

import sys
import urllib.parse
import requests
import vthread

requests.packages.urllib3.disable_warnings()

header = {
    "User-Agent": "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; fr-fr) AppleWebKit/125.5 (KHTML, like Gecko) Safari/125.9",
}

# config-start
testUrl = "https://www.ip138.com"
keyWord = "porxy ip"
proxyType = "SOCKS5"
timeoutNum = 5  # 设置超时
threadNumber = 50  # 设置线程数
proxiesFileName = "target.txt"
successFileName = "success.txt"

successProxyList = []
content = None


# config-end

@vthread.pool(threadNumber)
def verifyProxy(target, port, protocol, Num):
    keyWord = target
    if protocol == "HTTPS":
        proxies = {"http": "http://" + target + ":" + port, "https": "http://" + target + ":" + port}
    elif protocol == "SOCKS5":
        proxies = {"http": "socks5://" + target + ":" + port, "https": "socks5://" + target + ":" + port}
    else:  # 不指定协议时使用HTTP协议
        proxies = {"http": "http://" + target + ":" + port, "https": "http://" + target + ":" + port}
    try:
        content = requests.get(url=testUrl, headers=header, verify=False, timeout=timeoutNum, allow_redirects=False,
                               proxies=proxies)
        if content.status_code == 200 and keyWord in content.text:
            sys.stdout.write("\033[32m[o] - " + str(Num) + "个 校验成功! 代理可用:" + target + ":" + port + "\033[0m\n")
            successProxyList.append(target+":"+port)
    except Exception as e:
        sys.stdout.write("\033[31m[x] - " + str(Num) + "个 该代理不可用,请求错误:" + str(e)[0:100] + "\033[0m\n")


if __name__ == '__main__':
    proxyList = open(proxiesFileName, 'r').read().splitlines()
    for target in proxyList:
        targetParse = urllib.parse.urlparse(target)
        proxyType = str(targetParse.scheme)
        ip = str(targetParse.hostname)
        port = str(targetParse.port)
        verifyProxy(ip, port, proxyType, proxyList.index(target))
    vthread.pool.waitall()
    successWrite = open(successFileName, "w+")
    for line in successProxyList:
        successWrite.write(line + "\n")

赞(0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址