Skip to content

Commit

Permalink
compatible with wireguard:// and wg://
Browse files Browse the repository at this point in the history
  • Loading branch information
Toperlock committed Apr 17, 2024
1 parent 40db4bd commit f22eddb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def get_content_from_url(url, n=6):
print('处理: \033[31m' + url + '\033[0m')
# print('Đang tải link đăng ký: \033[31m' + url + '\033[0m')
prefixes = ["vmess://", "vless://", "ss://", "ssr://", "trojan://", "tuic://", "hysteria://", "hysteria2://",
"hy2://", "wg://", "http2://", "socks://", "socks5://"]
"hy2://", "wg://", "wireguard://", "http2://", "socks://", "socks5://"]
if any(url.startswith(prefix) for prefix in prefixes):
response_text = tool.noblankLine(url)
return response_text
Expand Down
10 changes: 5 additions & 5 deletions parsers/wg.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ def parse(data):
node = {
'tag': unquote(server_info.fragment) or tool.genName()+'_wireguard',
'type': 'wireguard',
'server': re.sub(r"\[|\]", "", server_info.netloc.rsplit(":", 1)[0]),
'server_port': int(server_info.netloc.rsplit(":", 1)[1]),
'private_key': netquery.get('privateKey'),
'peer_public_key': netquery.get('publicKey')
'server': re.sub(r"\[|\]", "", server_info.netloc.rsplit("@", 1)[-1].rsplit(":", 1)[0]),
'server_port': int(server_info.netloc.rsplit("@", 1)[-1].rsplit(":", 1)[1]),
'private_key': netquery.get('privateKey') or unquote(server_info.netloc.rsplit("@", 1)[0]),
'peer_public_key': netquery.get('publicKey') or netquery.get('publickey')
}
if netquery.get('reserved'):
reserved_value = netquery.get('reserved')
node['reserved'] = [int(val) for val in reserved_value.split(",")] if ',' in reserved_value else reserved_value
ip_value = netquery.get('ip')
ip_value = netquery.get('ip') or netquery.get('address')
if ',' in ip_value:
ipv4_value, ipv6_value = ip_value.split(",", 1)
ipv4_value = ipv4_value + "/32" if '/' not in ipv4_value else ipv4_value
Expand Down
3 changes: 3 additions & 0 deletions tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ def get_protocol(s):
if m.group(1) == 'hy2':
s = re.sub(r'^(.+?)://', 'hysteria2://', s)
m = re.search(r'^(.+?)://', s)
if m.group(1) == 'wireguard':
s = re.sub(r'^(.+?)://', 'wg://', s)
m = re.search(r'^(.+?)://', s)
if m.group(1) == 'http2':
s = re.sub(r'^(.+?)://', 'http://', s)
m = re.search(r'^(.+?)://', s)
Expand Down

0 comments on commit f22eddb

Please sign in to comment.