Skip to content

Commit

Permalink
Add port hopping (v1.11.0-beta.17+)
Browse files Browse the repository at this point in the history
  • Loading branch information
Toperlock committed Dec 30, 2024
1 parent cb3316e commit 9eb0a3c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion parsers/clash2base64.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', ''),
Expand Down
6 changes: 5 additions & 1 deletion parsers/hysteria2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand All @@ -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'] == '':
Expand Down

0 comments on commit 9eb0a3c

Please sign in to comment.