-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
128 lines (104 loc) · 3.84 KB
/
main.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from urllib import parse
import pyperclip
'''
华南农业大学 WebVPN 远程接入系统链接生成与还原工具
Author: [email protected]
Version: 22.8.1
'''
# 定义webVpn服务器地址信息
webVpnGateWayUrl = 'vpn.scau.edu.cn:8118'
webVpnScheme = 'http'
def welcome():
text = '''
_____ _________ __ __ _ __ __ _ ______ _ __
/ ___// ____/ | / / / / | | / /__ / /_| | / / __ \/ | / /
\__ \/ / / /| |/ / / / | | /| / / _ \/ __ \ | / / /_/ / |/ /
___/ / /___/ ___ / /_/ / | |/ |/ / __/ /_/ / |/ / ____/ /| /
/____/\____/_/ |_\____/____|__/|__/\___/_.___/|___/_/ /_/ |_/
/_____/
华南农业大学 WebVPN 远程接入系统链接生成与还原工具
Author:[email protected] Ver:22.8.1
Github: https://github.com/interestingcn/SCAU_WebVPNTools
'''
print(text)
# [ Direct ==> WebVPN ]
def url_to_webVpn(url):
# 去除结尾多余的 ’/‘
if str(url).endswith('/'):
url = url[:-1]
url = parse.urlparse(url)
if url.scheme == 'https':
scheme_sign = '-s'
else:
scheme_sign = ''
if url.port != 80 and url.port != None:
port_sign = f'-{url.port}-p'
else:
port_sign = ''
hostname = url.hostname.replace('.','-')
if url.query != '':
generateWebVpnUrl = f'{webVpnScheme}://{hostname}{port_sign}{scheme_sign}.{webVpnGateWayUrl}{url.path}?{url.query}'
else:
generateWebVpnUrl = f'{webVpnScheme}://{hostname}{port_sign}{scheme_sign}.{webVpnGateWayUrl}{url.path}'
return generateWebVpnUrl
# [ WebVPN ==> Direct ]
def webVpn_to_url(url):
# 去除结尾多余的 ’/‘
if str(url).endswith('/'):
url = url[:-1]
url = parse.urlparse(url)
hostname = url.netloc.replace('.'+webVpnGateWayUrl,'')
hostname = hostname.split('-')
if 's' in hostname:
scheme = 'https'
del hostname[hostname.index('s')]
else:
scheme = 'http'
if 'p' in hostname:
port = ':' + hostname[hostname.index('p') - 1]
# 因依赖参数'p'进行定位,此处销毁元素需注意先后顺序
del hostname[hostname.index('p') - 1]
del hostname[hostname.index('p')]
else:
port = ''
hostname = '.'.join(hostname)
if url.query != '':
return f'{scheme}://{hostname}{port}{url.path}?{url.query}'
else:
return f'{scheme}://{hostname}{port}{url.path}'
def isUrl(url):
url = parse.urlparse(url)
if url.netloc == '':
return False
else:
return True
def isWebVpnUrl(url):
url = parse.urlparse(url)
return str(url.netloc).endswith(webVpnGateWayUrl)
if __name__ == '__main__':
welcome()
print('[ Tips: 请直接从浏览器中复制所需URL粘贴至此(包括http/https),结果将自动保存在剪切板中. ]')
while True:
print('')
input_url = input('输入链接: ')
# 快速结束
if input_url == ' ':
exit()
# 从剪切板获取链接,需添加输入暂停代码
# input_url = pyperclip.paste()
if isUrl(input_url) == False:
print('当前地址有误,请重新输入')
continue
if isWebVpnUrl(input_url):
url_res = webVpn_to_url(input_url)
print('[ WebVPN ==> Direct ]: ' + url_res)
pyperclip.copy(url_res)
continue
else:
url_res = url_to_webVpn(input_url)
print('[ Direct ==> WebVPN ]: ' + url_res)
pyperclip.copy(url_res)
continue
exit()