Created
September 9, 2013 01:38
-
-
Save samurai00/6490401 to your computer and use it in GitHub Desktop.
set proxy on Mac using command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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