forked from Toperlock/sing-box-subscribe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsocks.py
25 lines (25 loc) · 929 Bytes
/
socks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import tool,json,re,urllib,sys
from urllib.parse import urlparse, parse_qs, unquote
def parse(data):
info = data[:]
server_info = urlparse(info)
node = {
'tag': unquote(server_info.fragment) or tool.genName()+'_socks',
'type': 'socks',
"version": "5",
'udp_over_tcp': {}
}
try:
netloc = (tool.b64Decode(server_info.netloc)).decode()
except:
netloc = server_info.netloc
if '@' in netloc:
_netloc = netloc.split("@")
node['server'] = re.sub(r"\[|\]", "", _netloc[1].rsplit(":", 1)[0])
node['server_port'] = int(_netloc[1].rsplit(":", 1)[1])
node['username'] = _netloc[0].split(":")[0]
node['password'] = _netloc[0].split(":")[1]
else:
node['server'] = re.sub(r"\[|\]", "", netloc.rsplit(":", 1)[0])
node['server_port'] = int(netloc.rsplit(":", 1)[1])
return (node)