Browse Source

feat: demo of shadowsocks test

master
Dnomd343 3 years ago
parent
commit
e82f5816ca
  1. 4
      ProxyBuilder/Shadowsocks.py
  2. 4
      ProxyBuilder/ShadowsocksR.py
  3. 50
      ProxyBuilder/builder.py
  4. 109
      ProxyBuilder/test/Shadowsocks.py
  5. 4
      ProxyBuilder/test/__init__.py
  6. 1
      demo.py

4
ProxyBuilder/Shadowsocks.py

@ -141,9 +141,9 @@ ssMethodList = { # shadowsocks各版本支持的加密方式
def __baseJSON(proxyInfo, socksPort): # 生成JSON基本结构 def __baseJSON(proxyInfo, socksPort): # 生成JSON基本结构
jsonContent = { jsonContent = {
'server': proxyInfo['server'], 'server': proxyInfo['server'],
'server_port': proxyInfo['port'], 'server_port': int(proxyInfo['port']),
'local_address': '127.0.0.1', 'local_address': '127.0.0.1',
'local_port': socksPort, 'local_port': int(socksPort),
'password': proxyInfo['password'], 'password': proxyInfo['password'],
'method': proxyInfo['method'], 'method': proxyInfo['method'],
} }

4
ProxyBuilder/ShadowsocksR.py

@ -82,9 +82,9 @@ def load(proxyInfo, socksPort, configFile): # ShadowsocksR配置载入
return None, None # 匹配不到混淆方式 return None, None # 匹配不到混淆方式
return [ 'ssr-local', '-c', configFile ], json.dumps({ return [ 'ssr-local', '-c', configFile ], json.dumps({
'server': proxyInfo['server'], 'server': proxyInfo['server'],
'server_port': proxyInfo['port'], 'server_port': int(proxyInfo['port']),
'local_address': '127.0.0.1', 'local_address': '127.0.0.1',
'local_port': socksPort, 'local_port': int(socksPort),
'password': proxyInfo['password'], 'password': proxyInfo['password'],
'method': proxyInfo['method'], 'method': proxyInfo['method'],
'protocol': proxyInfo['protocol'], 'protocol': proxyInfo['protocol'],

50
ProxyBuilder/builder.py

@ -92,13 +92,13 @@ def build(proxyInfo, configDir): # 构建代理节点连接
if os.path.exists(libcPath): # 定位libc.so文件 if os.path.exists(libcPath): # 定位libc.so文件
break break
exitWithMe = lambda: ctypes.CDLL(libcPath).prctl(1, 15) # SIGTERM exitWithMe = lambda: ctypes.CDLL(libcPath).prctl(1, 15) # SIGTERM
process = subprocess.Popen(startCommand, \ process = subprocess.Popen(startCommand,
stdout = subprocess.DEVNULL, \ stdout = subprocess.DEVNULL,
stderr = subprocess.DEVNULL, \ stderr = subprocess.DEVNULL,
preexec_fn = exitWithMe) # 子进程跟随退出 preexec_fn = exitWithMe) # 子进程跟随退出
except: except:
process = subprocess.Popen(startCommand, \ process = subprocess.Popen(startCommand,
stdout = subprocess.DEVNULL, \ stdout = subprocess.DEVNULL,
stderr = subprocess.DEVNULL) # prctl失败 回退正常启动 stderr = subprocess.DEVNULL) # prctl失败 回退正常启动
return { # 返回连接参数 return { # 返回连接参数
@ -132,4 +132,42 @@ def destroy(taskInfo): # 结束客户端并清理
except: pass except: pass
def test(): def test():
print("ProxyBuilder test") import requests
import ProxyBuilder.test as tester
data = tester.Shadowsocks.test(1080, 'dnomd343')
for field in data:
serverProcess = subprocess.Popen(
field['serverCommand'],
stdout = subprocess.DEVNULL,
stderr = subprocess.DEVNULL)
time.sleep(0.5) # 等待服务端启动完成
if serverProcess.poll() != None: # 服务端启动失败
print("server unexpected exit")
continue
print(field['caption'])
client = build(field['proxyInfo'], '/tmp/ProxyC')
time.sleep(0.5) # 等待客户端启动完成
if not check(client):
print("client unexpected exit") # 客户端启动失败
else:
try:
startTime = time.time_ns()
r = requests.get('http://gstatic.com/generate_204', proxies = {
'http': 'socks5://127.0.0.1:' + str(client['port']),
'https': 'socks5://127.0.0.1:' + str(client['port']),
})
if r.status_code == 204:
delay = (time.time_ns() - startTime) / (10 ** 6)
print(format(delay, '.2f') + 'ms')
else:
print("connect error")
except:
print("request error")
destroy(client) # 关闭客户端
time.sleep(0.3)
serverProcess.terminate() # 关闭服务端
time.sleep(0.3)
print()

109
ProxyBuilder/test/Shadowsocks.py

@ -0,0 +1,109 @@
#!/usr/bin/python
# -*- coding:utf-8 -*-
ssMethodList = [
'aes-128-gcm',
'aes-192-gcm',
'aes-256-gcm',
'aes-128-ctr',
'aes-192-ctr',
'aes-256-ctr',
'aes-128-ocb',
'aes-192-ocb',
'aes-256-ocb',
'aes-128-ofb',
'aes-192-ofb',
'aes-256-ofb',
'aes-128-cfb',
'aes-192-cfb',
'aes-256-cfb',
'aes-128-cfb1',
'aes-192-cfb1',
'aes-256-cfb1',
'aes-128-cfb8',
'aes-192-cfb8',
'aes-256-cfb8',
'aes-128-cfb128',
'aes-192-cfb128',
'aes-256-cfb128',
'camellia-128-cfb',
'camellia-192-cfb',
'camellia-256-cfb',
'camellia-128-cfb128',
'camellia-192-cfb128',
'camellia-256-cfb128',
'plain',
'none',
'table',
'rc4',
'rc4-md5',
'rc2-cfb',
'bf-cfb',
'cast5-cfb',
'des-cfb',
'idea-cfb',
'seed-cfb',
'salsa20',
'salsa20-ctr',
'xchacha20',
'chacha20',
'chacha20-ietf',
'chacha20-poly1305',
'chacha20-ietf-poly1305',
'xchacha20-ietf-poly1305'
]
def test(port, password):
testList = []
for method in ssMethodList:
proxyInfo = {
'type': 'ss',
'server': '127.0.0.1',
'port': str(port),
'password': password,
'method': method,
'plugin': '',
'pluginArg': '',
}
testInfo = 'test for ' + method
if method == 'plain' or method == 'none':
serverCommand = [
'ss-rust-server', '-U',
'-s', '0.0.0.0:' + str(port),
'-k', password,
'-m', method
]
elif method == 'salsa20-ctr':
serverCommand = [
'ss-bootstrap-server',
'--shadowsocks', 'ss-python-legacy-server',
'-p', str(port),
'-k', password,
'-m', method
]
else:
specialMethods = [
'aes-128-cfb128',
'aes-192-cfb128',
'aes-256-cfb128',
'camellia-128-cfb128',
'camellia-192-cfb128',
'camellia-256-cfb128',
]
if method in specialMethods:
method = 'mbedtls:' + method
serverCommand = [
'ss-bootstrap-server',
'--shadowsocks', 'ss-python-server',
'-p', str(port),
'-k', password,
'-m', method
]
if method == 'idea-cfb' or method == 'seed-cfb':
serverCommand.append('--libopenssl=libcrypto.so.1.0.0')
testList.append({
'caption': testInfo,
'proxyInfo': proxyInfo,
'serverCommand': serverCommand
})
return testList

4
ProxyBuilder/test/__init__.py

@ -0,0 +1,4 @@
#!/usr/bin/python
# -*- coding:utf-8 -*-
from ProxyBuilder.test import Shadowsocks

1
demo.py

@ -49,6 +49,7 @@ print(task)
time.sleep(1) time.sleep(1)
if Builder.check(task) == False: if Builder.check(task) == False:
print("error exit") print("error exit")
Builder.destroy(task)
else: else:
print("test with gstatic") print("test with gstatic")
checkSocksPort(task['port']) checkSocksPort(task['port'])

Loading…
Cancel
Save