自用梭子

栏目: Python · 发布时间: 7年前

内容简介:文章首发:
import multiprocessing
import random
import re
import sys
import time

import requests
import shadowsocks.local


def run_shadowsocks(host, port, password, method):
    sys.argv = sys.argv[:1]
    for arg in '-s {} -p {} -k {} -m {}'.format(host, port, password, method).split():
        sys.argv.append(arg)
    shadowsocks.local.main()


def run_from_page():
    print("Downloading servers")
    url = 'https://raw.githubusercontent.com/baijifeilong/resources/master/mastercrosswall/servers'
    print("Servers downloaded")
    text = requests.get(url).text
    lines = [line for line in text.splitlines() if re.match('(\d+/){3}\d+', line)][:18]
    random.shuffle(lines)

    for line in lines:
        _, host, port, password, method, _, _ = line.split()
        print('\nProxy: method={}, password={}, host={}, port={}'.format(method, password, host, port))
        process = multiprocessing.Process(target=run_shadowsocks,
                                          kwargs=dict(host=host, port=port, password=password, method=method))
        process.start()
        try:
            time.sleep(1)
            elapsed = verify_proxy()
            print("Valid proxy with elapsed {}".format(elapsed.microseconds / 1000_000))
            process.join()
        except Exception as e:
            print("Invalid proxy:", e)
            process.terminate()
            print("Terminated.")


def verify_proxy():
    rsp = requests.get('https://google.com', proxies=dict(https='socks5h://localhost:1080'), timeout=5)
    assert rsp.status_code is 200
    return rsp.elapsed


if __name__ == '__main__':
    run_from_page()

文章首发: https://baijifeilong.github.io


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

The Probabilistic Method Second Edition

The Probabilistic Method Second Edition

Noga Alon、Joel H. Spencer / Wiley-Blackwell / 2000 / $121.95

The leading reference on probabilistic methods in combinatorics-now expanded and updated When it was first published in 1991, The Probabilistic Method became instantly the standard reference on one......一起来看看 《The Probabilistic Method Second Edition》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具