-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmacos-proxy-env
More file actions
executable file
·41 lines (34 loc) · 1.33 KB
/
macos-proxy-env
File metadata and controls
executable file
·41 lines (34 loc) · 1.33 KB
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
#!/usr/bin/env python3
import os
import subprocess
proxy_types = ['http', 'https', 'socks']
proxy_vars = {'http': 'http_proxy',
'https': 'https_proxy',
'socks': 'all_proxy'}
proxy_protocols = {'http': 'http',
'https': 'http',
'socks': 'socks5'}
result = subprocess.run(['scutil', '--proxy'], stdout=subprocess.PIPE)
lines = result.stdout.decode('utf-8').splitlines()
for proxy_type in proxy_types:
addrkey = proxy_type.upper() + 'Proxy'
portkey = proxy_type.upper() + 'Port'
addr = ''
port = ''
for line in lines:
if addrkey in line:
addr = line.split()[-1]
if portkey in line:
port = line.split()[-1]
if addr != '' and port != '':
shell = os.environ['SHELL']
if shell.endswith('fish'):
print('set -xg %s "%s://%s:%s"' % (proxy_vars[proxy_type],
proxy_protocols[proxy_type],
addr,
port))
else:
print('export %s="%s://%s:%s"' % (proxy_vars[proxy_type],
proxy_protocols[proxy_type],
addr,
port))