diff --git a/parsers/clash2base64.py b/parsers/clash2base64.py index 3d6fc817d..7b3effcbc 100644 --- a/parsers/clash2base64.py +++ b/parsers/clash2base64.py @@ -260,10 +260,11 @@ def clash2v2ray(share_link): return link # TODO elif share_link['type'] == 'hysteria2': - link = "hysteria2://{auth}@{server}:{port}?insecure={allowInsecure}&obfs={obfs}&obfs-password={obfspassword}&pinSHA256={fingerprint}&sni={sni}&alpn={alpn}&upmbps={upmbps}&downmbps={downmbps}#{name}".format( + link = "hysteria2://{auth}@{server}:{port}{ports}?insecure={allowInsecure}&obfs={obfs}&obfs-password={obfspassword}&pinSHA256={fingerprint}&sni={sni}&alpn={alpn}&upmbps={upmbps}&downmbps={downmbps}#{name}".format( auth = share_link.get('password', share_link.get('auth', '')), server = share_link['server'], port = share_link['port'], + ports=",{}".format(share_link['ports']) if share_link.get('ports') else '', allowInsecure = '0' if share_link.get('skip-cert-verify', '') == False else '1', obfs = share_link.get('obfs', 'none'), obfspassword = share_link.get('obfs-password', ''), diff --git a/parsers/hysteria2.py b/parsers/hysteria2.py index 016c44cd1..54abab6e6 100644 --- a/parsers/hysteria2.py +++ b/parsers/hysteria2.py @@ -10,11 +10,13 @@ def parse(data): ) if server_info.path: server_info = server_info._replace(netloc=server_info.netloc + server_info.path, path="") + port_match = re.search(r':(\d+)', server_info.netloc) + ports_match = re.search(r',(\d+-\d+)', server_info.netloc) node = { 'tag': unquote(server_info.fragment) or tool.genName()+'_hysteria2', 'type': 'hysteria2', 'server': re.sub(r"\[|\]", "", server_info.netloc.split("@")[-1].rsplit(":", 1)[0]), - 'server_port': int(re.search(r'\d+', server_info.netloc.rsplit(":", 1)[-1].split(",")[0]).group()), + 'server_port': int(port_match.group(1)), "password": netquery['auth'] if netquery.get('auth') else server_info.netloc.split("@")[0].rsplit(":", 1)[-1], 'up_mbps': int(re.search(r'\d+', netquery.get('upmbps', '10')).group()), 'down_mbps': int(re.search(r'\d+', netquery.get('downmbps', '100')).group()), @@ -24,6 +26,8 @@ def parse(data): 'insecure': False } } + if ports_match: + node['server_ports'] = [ports_match.group(1)] if netquery.get('insecure') in ['1', 'true'] or netquery.get('allowInsecure') == '1': node['tls']['insecure'] = True if node['tls']['server_name'] == '':