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 |
#!/usr/bin/env python3 |
||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||
|
|
||||
Settings = { |
import time |
||||
'workDir': '/tmp/ProxyC', |
import requests |
||||
'serverBind': '127.0.0.1', |
from threading import Thread |
||||
'clientBind': '127.0.0.1', |
from Basis.Logger import logging |
||||
'site': 'www.bing.com', |
from Basis.Functions import md5Sum, hostFormat, checkPortStatus |
||||
'host': '343.re', |
|
||||
'cert': '/etc/ssl/certs/343.re/fullchain.pem', |
from Tester import Brook |
||||
'key': '/etc/ssl/certs/343.re/privkey.pem', |
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 |
#!/usr/bin/env python3 |
||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||
|
|
||||
import time |
import sys |
||||
import requests |
import Tester |
||||
from threading import Thread |
from Tester import testEntry |
||||
|
|
||||
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 |
|
||||
|
|
||||
from Basis.Logger import logging |
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: |
[ITEM]: ss / ss-all / ssr / vmess / vless / trojan / trojan-go / brook / hysteria |
||||
for i in range(times): |
|
||||
if not checkPortStatus(port): # port occupied |
|
||||
return True |
|
||||
time.sleep(delay / 1000) # default wait 100ms |
|
||||
return False # timeout |
|
||||
|
|
||||
|
[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) |
def getArg(field: str) -> str or None: |
||||
errFlag = False |
|
||||
socks5 = '%s:%i' % ( |
|
||||
hostFormat(testObj['socks']['addr'], v6Bracket = True), |
|
||||
testObj['socks']['port'] |
|
||||
) |
|
||||
try: |
try: |
||||
request = requests.get( |
index = sys.argv.index(field) |
||||
'http://iserv.scutbot.cn', |
return sys.argv[index + 1] |
||||
proxies = { |
except: |
||||
'http': 'socks5://' + socks5, |
return None |
||||
'https': 'socks5://' + socks5, |
|
||||
}, |
if '--help' in sys.argv: |
||||
timeout = 10 |
print(helpMsg) |
||||
) |
sys.exit(0) |
||||
request.raise_for_status() |
if len(sys.argv) > 1 and not sys.argv[1].startswith('--'): |
||||
logging.info('socks5 %s -> ok' % socks5) |
testItem = sys.argv[1] |
||||
except Exception as exp: |
if getArg('--url') is not None: |
||||
logging.error('socks5 %s -> error' % socks5) |
testUrl = getArg('--url') |
||||
logging.error('requests exception\n' + str(exp)) |
if getArg('--thread') is not None: |
||||
errFlag = True |
threadNum = int(getArg('--thread')) |
||||
|
if getArg('--filter') is not None: |
||||
testObj['client'].quit() |
testFilter = set(getArg('--filter').split(',')) |
||||
testObj['server'].quit() |
|
||||
if errFlag: |
logging.critical('test item: ' + ('all' if testItem is None else testItem)) |
||||
logging.warning('client info') |
logging.critical('filter: %s' % testFilter) |
||||
logging.error('command -> %s' % testObj['client'].cmd) |
logging.critical('url: ' + testUrl) |
||||
logging.error('envVar -> %s' % testObj['client'].env) |
logging.critical('thread number: %i' % threadNum) |
||||
logging.error('file -> %s' % testObj['client'].file) |
logging.critical('TEST START') |
||||
logging.warning('client capture output') |
if testItem is not None: |
||||
logging.error('\n' + str(testObj['client'].output)) |
Tester.test(testEntry[testItem], threadNum, testUrl, testFilter) |
||||
logging.warning('server info') |
else: |
||||
logging.error('command -> %s' % testObj['server'].cmd) |
for item in testEntry: |
||||
logging.error('envVar -> %s' % testObj['server'].env) |
if item == ('ss' if '--all' in sys.argv else 'ss-all'): # skip ss / ss-all |
||||
logging.error('file -> %s' % testObj['server'].file) |
continue |
||||
logging.warning('server capture output') |
logging.critical('TEST ITEM -> ' + item) |
||||
logging.error('\n' + str(testObj['server'].output)) |
Tester.test(testEntry[item], threadNum, testUrl, testFilter) |
||||
|
logging.critical('TEST COMPLETE') |
||||
|
|
||||
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') |
|
||||
|
Loading…
Reference in new issue