Skip to content

Instantly share code, notes, and snippets.

@EkkoG
Created April 12, 2016 14:46
Show Gist options
  • Save EkkoG/a2abec6e8d0929128e17203779b40557 to your computer and use it in GitHub Desktop.
Save EkkoG/a2abec6e8d0929128e17203779b40557 to your computer and use it in GitHub Desktop.
#!/bin/bash
currentInterface=$(networksetup -listnetworkserviceorder | \
awk -F'\\) ' '/\(1\)/ {print $2}')
state=$(networksetup -getwebproxy wi-fi | grep "No")
HTTP_PORT=6152
SOCK_PORT=6153
if [ -n "$state" ]; then
echo "Turning on proxy"
networksetup -setsecurewebproxy $currentInterface 127.0.0.1 $HTTP_PORT
networksetup -setwebproxy $currentInterface 127.0.0.1 $HTTP_PORT
networksetup -setsocksfirewallproxy $currentInterface 127.0.0.1 $SOCK_PORT
networksetup -setwebproxystate $currentInterface on
networksetup -setsecurewebproxystate $currentInterface on
networksetup -setsocksfirewallproxystate $currentInterface on
else
echo "Turning off proxy"
networksetup -setwebproxystate $currentInterface off
networksetup -setsecurewebproxystate $currentInterface off
networksetup -setsocksfirewallproxystate $currentInterface off
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment