diff --git a/ProxyFilter/Brook.py b/ProxyFilter/Brook.py index 317b163..20008e2 100644 --- a/ProxyFilter/Brook.py +++ b/ProxyFilter/Brook.py @@ -14,7 +14,7 @@ brookFilterRules = { 'server': { 'optional': True, 'type': str, - 'format': baseFunc.toStrTidy, + 'format': baseFunc.toHost, 'filter': baseFunc.isHost, 'errMsg': 'Illegal server address' }, diff --git a/ProxyFilter/baseFunc.py b/ProxyFilter/baseFunc.py index 33eba89..65a00c9 100644 --- a/ProxyFilter/baseFunc.py +++ b/ProxyFilter/baseFunc.py @@ -127,6 +127,13 @@ def toStrTidy(raw) -> str: # change to str with trim and lower return toStr(raw).strip().lower() +def toHost(raw) -> str: # format to IP address or domain + raw = toStrTidy(raw) + if raw[:1] == '[' and raw[-1:] == ']': # [IPv6] + raw = raw[1:-1] + return raw + + class filterException(Exception): # 检测异常 def __init__(self, reason): self.reason = reason diff --git a/ProxyTester/Brook.py b/ProxyTester/Brook.py index 8be4f70..62011a5 100644 --- a/ProxyTester/Brook.py +++ b/ProxyTester/Brook.py @@ -1,6 +1,8 @@ #!/usr/bin/python # -*- coding:utf-8 -*- +import copy + testConfig = {} def __originConfig() -> dict: @@ -8,7 +10,7 @@ def __originConfig() -> dict: 'caption': 'Brook original', 'client': { 'type': 'brook', - 'server': testConfig['host'], + 'server': testConfig['bind'], 'port': testConfig['port'], 'passwd': testConfig['passwd'] }, @@ -25,7 +27,7 @@ def __wsConfig() -> dict: 'caption': 'Brook websocket', 'client': { 'type': 'brook', - 'server': testConfig['host'], + 'server': testConfig['bind'], 'port': testConfig['port'], 'passwd': testConfig['passwd'], 'ws': { @@ -47,7 +49,7 @@ def __wssConfig() -> dict: 'caption': 'Brook websocket with TLS', 'client': { 'type': 'brook', - 'server': testConfig['host'], + 'server': testConfig['bind'], 'port': testConfig['port'], 'passwd': testConfig['passwd'], 'ws': { @@ -60,7 +62,7 @@ def __wssConfig() -> dict: }, 'server': [ 'brook', 'wssserver', - '--domainaddress', testConfig['host'] + ':' + str(testConfig['port']), + '--domainaddress', testConfig['bind'] + ':' + str(testConfig['port']), '--cert', testConfig['cert'], '--certkey', testConfig['key'], '--password', testConfig['passwd'], @@ -85,7 +87,9 @@ def __brookConfig(brookConfig: dict) -> dict: def test(config: dict) -> list: global testConfig - testConfig = config + testConfig = copy.deepcopy(config) + if testConfig['bind'].find(':') >= 0: + testConfig['bind'] = '[' + testConfig['bind'] + ']' return [ __brookConfig(__originConfig()), __brookConfig(__wsConfig()), diff --git a/Test.py b/Test.py index 4b95dc5..903c01a 100644 --- a/Test.py +++ b/Test.py @@ -15,7 +15,8 @@ testConfig = { 'passwd': 'dnomd343', 'host': 'local.343.re', 'path': '/test', - 'bind': '127.0.0.1', + 'bind': '::1', + # 'bind': '127.0.0.1', 'service': 'dnomd343', 'file': '/tmp/proxycTest.json', 'cert': '/etc/ssl/certs/343.re/fullchain.pem',