内容简介:文章首发:
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()
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- 开源一个自用的Android事件分发中心库,实现类似系统广播功能。
- 开源一个自用的Android IM库,基于Netty+TCP+Protobuf实现。
- 程序员亲自用代码给敲出飘落的雪花!网友:大神收我吧!
- 微信自用高性能通用key-value组件MMKV已开源!
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。