Browse Source

update: enhance ipv6 functions

master
dnomd343 2 years ago
parent
commit
f47d8687fe
  1. 8
      Basis/Functions.py
  2. 2
      Dockerfile
  3. 18
      Tester/Plugin.py
  4. 4
      Tester/Shadowsocks.py
  5. 4
      Tester/ShadowsocksR.py
  6. 14
      test.py

8
Basis/Functions.py

@ -5,6 +5,7 @@ import time
import psutil import psutil
import random import random
import hashlib import hashlib
from IPy import IP
from Basis.Logger import logging from Basis.Logger import logging
@ -12,6 +13,13 @@ def md5Sum(data: str, encode: str = 'UTF-8') -> str:
return hashlib.md5(data.encode(encoding = encode)).hexdigest() return hashlib.md5(data.encode(encoding = encode)).hexdigest()
def ipFormat(ipAddr: str, v6Bracket: bool = False) -> str:
ip = IP(ipAddr)
if v6Bracket and ip.version() == 6:
return '[%s]' % str(ip) # [IPv6]
return str(ip) # IPv4 / IPV6
def genFlag(length: int = 12) -> str: # generate random task flag def genFlag(length: int = 12) -> str: # generate random task flag
flag = '' flag = ''
for i in range(0, length): for i in range(0, length):

2
Dockerfile

@ -465,5 +465,5 @@ COPY --from=dnsproxy /tmp/dnsproxy /asset/usr/bin/
FROM python:3.10-alpine3.16 FROM python:3.10-alpine3.16
RUN \ RUN \
apk add --no-cache boost-program_options c-ares glib libev libsodium libstdc++ mbedtls pcre && \ apk add --no-cache boost-program_options c-ares glib libev libsodium libstdc++ mbedtls pcre && \
pip3 --no-cache-dir install colorlog pysocks requests pip3 --no-cache-dir install colorlog pysocks requests IPy
COPY --from=asset /asset / COPY --from=asset /asset /

18
Tester/Plugin.py

@ -7,18 +7,24 @@ import json
from Basis.Logger import logging from Basis.Logger import logging
from Basis.Process import Process from Basis.Process import Process
from Basis.Methods import plugins from Basis.Methods import plugins
from Basis.Functions import genFlag, getAvailablePort from Basis.Functions import genFlag
from Basis.Functions import ipFormat
from Basis.Functions import getAvailablePort
settings = { settings = {
'serverBind': '127.0.0.1', 'serverBind': '127.0.0.1',
'workDir': '/tmp/ProxyC', 'workDir': '/tmp/ProxyC',
'site': 'www.bing.com',
'host': '343.re',
'cert': '/etc/ssl/certs/343.re/fullchain.pem',
'key': '/etc/ssl/certs/343.re/privkey.pem',
} }
pluginParams = { pluginParams = {
'SITE': 'www.bing.com', 'SITE': settings['site'],
'HOST': '343.re', 'HOST': settings['host'],
'CERT': '/etc/ssl/certs/343.re/fullchain.pem', 'CERT': settings['cert'],
'KEY': '/etc/ssl/certs/343.re/privkey.pem', 'KEY': settings['key'],
'PATH': '/' + genFlag(length = 6), 'PATH': '/' + genFlag(length = 6),
'PASSWD': genFlag(length = 8), 'PASSWD': genFlag(length = 8),
} }
@ -270,7 +276,7 @@ def ssInject(server: Process, pluginInfo: dict) -> Process:
ssConfig = json.loads(server.file[0]['content']) # modify origin config ssConfig = json.loads(server.file[0]['content']) # modify origin config
ssConfig.pop('plugin') # remove plugin option ssConfig.pop('plugin') # remove plugin option
ssConfig.pop('plugin_opts') ssConfig.pop('plugin_opts')
rabbitBind = ('[%s]' if ':' in ssConfig['server'] else '%s') % ssConfig['server'] # ipv4 / [ipv6] rabbitBind = ipFormat(ssConfig['server'], v6Bracket = True) # ipv4 / [ipv6]
rabbitPort = ssConfig['server_port'] rabbitPort = ssConfig['server_port']
ssConfig['server'] = '127.0.0.1' # SIP003 use ipv4 localhost for communication ssConfig['server'] = '127.0.0.1' # SIP003 use ipv4 localhost for communication
ssConfig['server_port'] = int(pluginInfo['server']['param']) # aka ${RABBIT_PORT} ssConfig['server_port'] = int(pluginInfo['server']['param']) # aka ${RABBIT_PORT}

4
Tester/Shadowsocks.py

@ -15,7 +15,9 @@ from Basis.Functions import genFlag, getAvailablePort
settings = { settings = {
'serverBind': '127.0.0.1', 'serverBind': '127.0.0.1',
'clientBind': '127.0.0.1', # aka socks5 address 'clientBind': '127.0.0.1',
# 'serverBind': '::1',
# 'clientBind': '::1',
'workDir': '/tmp/ProxyC' 'workDir': '/tmp/ProxyC'
} }

4
Tester/ShadowsocksR.py

@ -11,7 +11,9 @@ from Basis.Methods import ssrMethods, ssrProtocols, ssrObfuscations
settings = { settings = {
'serverBind': '127.0.0.1', 'serverBind': '127.0.0.1',
'clientBind': '127.0.0.1', # aka socks5 address 'clientBind': '127.0.0.1',
# 'serverBind': '::1',
# 'clientBind': '::1',
'workDir': '/tmp/ProxyC' 'workDir': '/tmp/ProxyC'
} }

14
test.py

@ -7,6 +7,7 @@ from threading import Thread
from Tester import Shadowsocks from Tester import Shadowsocks
from Tester import ShadowsocksR from Tester import ShadowsocksR
from Basis.Logger import logging from Basis.Logger import logging
from Basis.Functions import ipFormat
from Basis.Functions import checkPortStatus from Basis.Functions import checkPortStatus
@ -31,19 +32,23 @@ def test(testObj: dict) -> None:
time.sleep(1) time.sleep(1)
errFlag = False errFlag = False
socks5 = '%s:%i' % (
ipFormat(testObj['socks']['addr'], v6Bracket = True),
testObj['socks']['port']
)
try: try:
request = requests.get( request = requests.get(
'http://iserv.scutbot.cn', 'http://iserv.scutbot.cn',
proxies = { proxies = {
'http': 'socks5://127.0.0.1:%i' % testObj['socks']['port'], 'http': 'socks5://' + socks5,
'https': 'socks5://127.0.0.1:%i' % testObj['socks']['port'], 'https': 'socks5://' + socks5,
}, },
timeout = 10 timeout = 10
) )
request.raise_for_status() request.raise_for_status()
logging.info('socks5 127.0.0.1:%i -> ok' % testObj['socks']['port']) logging.info('socks5 %s -> ok' % socks5)
except Exception as exp: except Exception as exp:
logging.error('socks5 127.0.0.1:%i -> error' % testObj['socks']['port']) logging.error('socks5 %s -> error' % socks5)
logging.error('requests exception\n' + str(exp)) logging.error('requests exception\n' + str(exp))
errFlag = True errFlag = True
@ -84,6 +89,7 @@ def runTest(testIter: iter, threadNum: int):
ss = Shadowsocks.load(isExtra = True) ss = Shadowsocks.load(isExtra = True)
# ss = Shadowsocks.load(isExtra = False)
ssr = ShadowsocksR.load() ssr = ShadowsocksR.load()
logging.critical('test start') logging.critical('test start')

Loading…
Cancel
Save