自用梭子

栏目: 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


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

查看所有标签

猜你喜欢:

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

Practical Vim, Second Edition

Practical Vim, Second Edition

Drew Neil / The Pragmatic Bookshelf / 2015-10-31 / USD 29.00

Vim is a fast and efficient text editor that will make you a faster and more efficient developer. It’s available on almost every OS, and if you master the techniques in this book, you’ll never need an......一起来看看 《Practical Vim, Second Edition》 这本书的介绍吧!

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

Base64 编码/解码

MD5 加密
MD5 加密

MD5 加密工具

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

HSV CMYK互换工具