自用梭子

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

内容简介:文章首发:
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


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

查看所有标签

猜你喜欢:

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

Programming Rust

Programming Rust

Jim Blandy / O'Reilly Media / 2016-8-25 / GBP 47.99

This practical book introduces systems programmers to Rust, the new and cutting-edge language that’s still in the experimental/lab stage. You’ll learn how Rust offers the rare and valuable combination......一起来看看 《Programming Rust》 这本书的介绍吧!

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

html转js在线工具
html转js在线工具

html转js在线工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具