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()