mirror of https://github.com/dnomd343/ProxyC
dnomd343
2 years ago
14 changed files with 198 additions and 168 deletions
@ -0,0 +1,12 @@ |
|||
#!/usr/bin/env python3 |
|||
# -*- coding: utf-8 -*- |
|||
|
|||
Settings = { |
|||
'workDir': '/tmp/ProxyC', |
|||
'serverBind': '127.0.0.1', |
|||
'clientBind': '127.0.0.1', |
|||
'site': 'www.bing.com', |
|||
'host': '343.re', |
|||
'cert': '/etc/ssl/certs/343.re/fullchain.pem', |
|||
'key': '/etc/ssl/certs/343.re/privkey.pem', |
|||
} |
@ -1,12 +1,109 @@ |
|||
#!/usr/bin/env python3 |
|||
# -*- coding: utf-8 -*- |
|||
|
|||
Settings = { |
|||
'workDir': '/tmp/ProxyC', |
|||
'serverBind': '127.0.0.1', |
|||
'clientBind': '127.0.0.1', |
|||
'site': 'www.bing.com', |
|||
'host': '343.re', |
|||
'cert': '/etc/ssl/certs/343.re/fullchain.pem', |
|||
'key': '/etc/ssl/certs/343.re/privkey.pem', |
|||
import time |
|||
import requests |
|||
from threading import Thread |
|||
from Basis.Logger import logging |
|||
from Basis.Functions import md5Sum, hostFormat, checkPortStatus |
|||
|
|||
from Tester import Brook |
|||
from Tester import VMess |
|||
from Tester import VLESS |
|||
from Tester import Trojan |
|||
from Tester import TrojanGo |
|||
from Tester import Hysteria |
|||
from Tester import Shadowsocks |
|||
from Tester import ShadowsocksR |
|||
|
|||
testEntry = { |
|||
'ss': Shadowsocks.load(), |
|||
'ss-all': Shadowsocks.load(isExtra = True), |
|||
'ssr': ShadowsocksR.load(), |
|||
'vmess': VMess.load(), |
|||
'vless': VLESS.load(), |
|||
'trojan': Trojan.load(), |
|||
'trojan-go': TrojanGo.load(), |
|||
'brook': Brook.load(), |
|||
'hysteria': Hysteria.load(), |
|||
} |
|||
|
|||
|
|||
def waitPort(port: int, times: int = 100, delay: int = 100) -> bool: # wait until port occupied |
|||
for i in range(times): |
|||
if not checkPortStatus(port): # port occupied |
|||
return True |
|||
time.sleep(delay / 1000) # default wait 100ms |
|||
return False # timeout |
|||
|
|||
|
|||
def httpCheck(socksInfo: dict, url: str, timeout: int = 10): |
|||
socksProxy = 'socks5://%s:%i' % (hostFormat(socksInfo['addr'], v6Bracket = True), socksInfo['port']) |
|||
try: |
|||
proxy = { |
|||
'http': socksProxy, |
|||
'https': socksProxy, |
|||
} |
|||
request = requests.get(url, timeout = timeout, proxies = proxy) |
|||
request.raise_for_status() |
|||
logging.info('%s -> ok' % socksProxy) |
|||
except Exception as exp: |
|||
logging.error('%s -> error' % socksProxy) |
|||
logging.error('requests exception\n' + str(exp)) |
|||
raise RuntimeError('socks5 test failed') |
|||
|
|||
|
|||
def runTest(testInfo: dict, testUrl: str, testFilter: set or None, delay: int = 1) -> None: |
|||
testInfo['hash'] = md5Sum(testInfo['caption'])[:12] |
|||
if testFilter is not None and testInfo['hash'] not in testFilter: return |
|||
logging.warning('[%s] %s' % (testInfo['hash'], testInfo['caption'])) |
|||
testInfo['server'].start() # start test server |
|||
if waitPort(testInfo['interface']['port']): # wait for server |
|||
logging.debug('server start complete') |
|||
testInfo['client'].start() # start test client |
|||
if waitPort(testInfo['socks']['port']): # wait for client |
|||
logging.debug('client start complete') |
|||
try: |
|||
logging.debug('start test process') |
|||
time.sleep(delay) |
|||
httpCheck(testInfo['socks'], testUrl) |
|||
except: |
|||
# client debug info |
|||
logging.warning('client info') |
|||
logging.error('command -> %s' % testInfo['client'].cmd) |
|||
logging.error('envVar -> %s' % testInfo['client'].env) |
|||
logging.error('file -> %s' % testInfo['client'].file) |
|||
logging.warning('client capture output') |
|||
logging.error('\n%s' % testInfo['client'].output) |
|||
# server debug info |
|||
logging.warning('server info') |
|||
logging.error('command -> %s' % testInfo['server'].cmd) |
|||
logging.error('envVar -> %s' % testInfo['server'].env) |
|||
logging.error('file -> %s' % testInfo['server'].file) |
|||
logging.warning('server capture output') |
|||
logging.error('\n%s' % testInfo['server'].output) |
|||
finally: |
|||
testInfo['client'].quit() |
|||
testInfo['server'].quit() |
|||
|
|||
|
|||
def test(testIter: iter, threadNum: int, testUrl: str, testFilter: set or None = None): |
|||
threads = [] |
|||
while True: # infinite loop |
|||
try: |
|||
for thread in threads: |
|||
if thread.is_alive(): continue |
|||
threads.remove(thread) # remove dead thread |
|||
if len(threads) < threadNum: |
|||
for i in range(threadNum - len(threads)): # start threads within limit |
|||
thread = Thread( # create new thread |
|||
target = runTest, |
|||
args = (next(testIter), testUrl, testFilter) |
|||
) |
|||
thread.start() |
|||
threads.append(thread) # record thread info |
|||
time.sleep(0.1) |
|||
except StopIteration: # traverse completed |
|||
break |
|||
for thread in threads: # wait until all threads exit |
|||
thread.join() |
|||
|
@ -1,118 +1,59 @@ |
|||
#!/usr/bin/env python3 |
|||
# -*- coding: utf-8 -*- |
|||
|
|||
import time |
|||
import requests |
|||
from threading import Thread |
|||
|
|||
from Tester import Brook |
|||
from Tester import VMess |
|||
from Tester import VLESS |
|||
from Tester import Trojan |
|||
from Tester import TrojanGo |
|||
from Tester import Hysteria |
|||
from Tester import Shadowsocks |
|||
from Tester import ShadowsocksR |
|||
|
|||
import sys |
|||
import Tester |
|||
from Tester import testEntry |
|||
from Basis.Logger import logging |
|||
from Basis.Functions import hostFormat |
|||
from Basis.Functions import checkPortStatus |
|||
|
|||
threadNum = 16 |
|||
testItem = None |
|||
testFilter = None |
|||
testUrl = 'http://baidu.com' |
|||
helpMsg = ''' |
|||
./test.py [ITEM] [OPTIONS] |
|||
|
|||
def waitForStart(port: int, times: int = 100, delay: int = 100) -> bool: |
|||
for i in range(times): |
|||
if not checkPortStatus(port): # port occupied |
|||
return True |
|||
time.sleep(delay / 1000) # default wait 100ms |
|||
return False # timeout |
|||
[ITEM]: ss / ss-all / ssr / vmess / vless / trojan / trojan-go / brook / hysteria |
|||
|
|||
[OPTIONS]: |
|||
--thread NUM thread number |
|||
--url URL http check url |
|||
--filter ID1[,ID2...] test the specified id |
|||
--all test extra shadowsocks items |
|||
--help show this message |
|||
''' |
|||
|
|||
def test(testObj: dict) -> None: |
|||
logging.warning(testObj['title']) |
|||
testObj['server'].start() |
|||
time.sleep(0.2) |
|||
testObj['client'].start() |
|||
if waitForStart(testObj['interface']['port']): |
|||
logging.debug('server start complete') |
|||
if waitForStart(testObj['socks']['port']): |
|||
logging.debug('client start complete') |
|||
logging.debug('start test process') |
|||
|
|||
time.sleep(1) |
|||
errFlag = False |
|||
socks5 = '%s:%i' % ( |
|||
hostFormat(testObj['socks']['addr'], v6Bracket = True), |
|||
testObj['socks']['port'] |
|||
) |
|||
def getArg(field: str) -> str or None: |
|||
try: |
|||
request = requests.get( |
|||
'http://iserv.scutbot.cn', |
|||
proxies = { |
|||
'http': 'socks5://' + socks5, |
|||
'https': 'socks5://' + socks5, |
|||
}, |
|||
timeout = 10 |
|||
) |
|||
request.raise_for_status() |
|||
logging.info('socks5 %s -> ok' % socks5) |
|||
except Exception as exp: |
|||
logging.error('socks5 %s -> error' % socks5) |
|||
logging.error('requests exception\n' + str(exp)) |
|||
errFlag = True |
|||
|
|||
testObj['client'].quit() |
|||
testObj['server'].quit() |
|||
if errFlag: |
|||
logging.warning('client info') |
|||
logging.error('command -> %s' % testObj['client'].cmd) |
|||
logging.error('envVar -> %s' % testObj['client'].env) |
|||
logging.error('file -> %s' % testObj['client'].file) |
|||
logging.warning('client capture output') |
|||
logging.error('\n' + str(testObj['client'].output)) |
|||
logging.warning('server info') |
|||
logging.error('command -> %s' % testObj['server'].cmd) |
|||
logging.error('envVar -> %s' % testObj['server'].env) |
|||
logging.error('file -> %s' % testObj['server'].file) |
|||
logging.warning('server capture output') |
|||
logging.error('\n' + str(testObj['server'].output)) |
|||
|
|||
|
|||
def runTest(testIter: iter, threadNum: int): |
|||
threads = [] |
|||
while True: # infinite loop |
|||
try: |
|||
for thread in threads: |
|||
if thread.is_alive(): continue |
|||
threads.remove(thread) # remove dead thread |
|||
if len(threads) < threadNum: |
|||
for i in range(threadNum - len(threads)): # start threads within limit |
|||
thread = Thread(target=test, args=(next(testIter),)) # create new thread |
|||
thread.start() |
|||
threads.append(thread) # record thread info |
|||
time.sleep(0.1) |
|||
except StopIteration: # traverse completed |
|||
break |
|||
for thread in threads: # wait until all threads exit |
|||
thread.join() |
|||
|
|||
|
|||
ss = Shadowsocks.load(isExtra = True) |
|||
# ss = Shadowsocks.load(isExtra = False) |
|||
ssr = ShadowsocksR.load() |
|||
vmess = VMess.load() |
|||
vless = VLESS.load() |
|||
trojan = Trojan.load() |
|||
trojanGo = TrojanGo.load() |
|||
brook = Brook.load() |
|||
hysteria = Hysteria.load() |
|||
|
|||
logging.critical('test start') |
|||
runTest(ss, 64) |
|||
runTest(ssr, 64) |
|||
runTest(vmess, 64) |
|||
runTest(vless, 64) |
|||
runTest(trojan, 64) |
|||
runTest(trojanGo, 64) |
|||
runTest(brook, 64) |
|||
runTest(hysteria, 64) |
|||
logging.critical('test complete') |
|||
index = sys.argv.index(field) |
|||
return sys.argv[index + 1] |
|||
except: |
|||
return None |
|||
|
|||
if '--help' in sys.argv: |
|||
print(helpMsg) |
|||
sys.exit(0) |
|||
if len(sys.argv) > 1 and not sys.argv[1].startswith('--'): |
|||
testItem = sys.argv[1] |
|||
if getArg('--url') is not None: |
|||
testUrl = getArg('--url') |
|||
if getArg('--thread') is not None: |
|||
threadNum = int(getArg('--thread')) |
|||
if getArg('--filter') is not None: |
|||
testFilter = set(getArg('--filter').split(',')) |
|||
|
|||
logging.critical('test item: ' + ('all' if testItem is None else testItem)) |
|||
logging.critical('filter: %s' % testFilter) |
|||
logging.critical('url: ' + testUrl) |
|||
logging.critical('thread number: %i' % threadNum) |
|||
logging.critical('TEST START') |
|||
if testItem is not None: |
|||
Tester.test(testEntry[testItem], threadNum, testUrl, testFilter) |
|||
else: |
|||
for item in testEntry: |
|||
if item == ('ss' if '--all' in sys.argv else 'ss-all'): # skip ss / ss-all |
|||
continue |
|||
logging.critical('TEST ITEM -> ' + item) |
|||
Tester.test(testEntry[item], threadNum, testUrl, testFilter) |
|||
logging.critical('TEST COMPLETE') |
|||
|
Loading…
Reference in new issue