From 983a30e1978f0d8acefcafc3cb2b55a420b4e7c1 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Wed, 13 Nov 2024 17:35:32 +0800 Subject: [PATCH] bugfix --- proxy | 15 +++++++++++++++ socks | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100755 proxy create mode 100755 socks diff --git a/proxy b/proxy new file mode 100755 index 0000000..2db1366 --- /dev/null +++ b/proxy @@ -0,0 +1,15 @@ +### +# need change username and domain to your +# username +# domain +start_proxy() +{ + while [ "1" = "1" ] + do + ssh -N -D 0.0.0.0:1086 username@domain + done +} + +start_proxy & +socks start +echo "proxy started" diff --git a/socks b/socks new file mode 100755 index 0000000..c8a2bf9 --- /dev/null +++ b/socks @@ -0,0 +1,46 @@ +#!/usr/bin/python3 + +import sh +def getNetWorkServices(): + x = sh.networksetup('-listallnetworkservices'); + s = x.split('\n') + s = [ i for i in s if i!='' ] + s = s[1:] + print(s); + return s + +def getIpByService(s): + print('s=', s) + x = sh.networksetup('-getinfo', s) + lines = x.split('\n') + start = 'IP address: ' + for l in lines: + if l.startswith(start): + return l[len(start):] + return None + +def disableProxy(): + services = getNetWorkServices() + ret = {s:getIpByService(s) for s in services} + for s,ip in ret.items(): + if ip is not None: + sh.networksetup('-setsocksfirewallproxystate', s, 'off') + print(s, ip, 'socks stoped') + +def enableProxy(): + services = getNetWorkServices() + ret = {s:getIpByService(s) for s in services} + for s,ip in ret.items(): + if ip is not None: + ip_domain = '.'.join(ip.split('.')[:-1]) + sh.networksetup('-setsocksfirewallproxy', s, ip, '1086') + sh.networksetup('-setproxybypassdomains', s, ip_domain) + print(s, ip, 'socks started') + + +if __name__ == '__main__': + import sys + if len(sys.argv) > 1 and sys.argv[1] == 'stop': + disableProxy() + else: + enableProxy()