Skip to content

Instantly share code, notes, and snippets.

@samurai00
Created September 9, 2013 01:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samurai00/6490401 to your computer and use it in GitHub Desktop.
Save samurai00/6490401 to your computer and use it in GitHub Desktop.
set proxy on Mac using command
#!/bin/bash
USAGE="usage:set-proxy {eth|wifi} {socks|http|auto} {on|off|set} [addr] [port]"
if [[ $# -lt 3 ]]; then
echo ${USAGE}
exit 1
fi
INTERFACE=""
case $1 in
eth|tbt-eth)
INTERFACE="tbt-eth"
;;
wifi|wi-fi|Wi-Fi)
INTERFACE="Wi-Fi"
;;
*)
echo ${USAGE}
exit 1
;;
esac
TYPE=""
PARAM_COUNT=5
case $2 in
socks)
TYPE="socksfirewallproxy"
;;
http)
TYPE="webproxy"
;;
auto)
TYPE="autoproxy"
PARAM_COUNT=4
;;
*)
echo ${USAGE}
exit 1
;;
esac
case $3 in
on|off)
sudo networksetup -set${TYPE}state ${INTERFACE} $3
;;
set)
if [[ $# -lt $PARAM_COUNT ]]; then
echo "param not enough"
exit 1
fi
if [[ "$2" = "auto" ]]; then
sudo networksetup -set${TYPE}url ${INTERFACE} $4
else
sudo networksetup -set${TYPE} ${INTERFACE} $4 $5 off
fi
;;
*)
echo ${USAGE}
exit 1
;;
esac
if [[ "$2" = "auto" ]]; then
networksetup -get${TYPE}url ${INTERFACE}
else
networksetup -get${TYPE} ${INTERFACE}
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment