Created
November 14, 2017 18:36
-
-
Save gregjhogan/bb4eb4f501c8df862e462075409c9a82 to your computer and use it in GitHub Desktop.
proxy settings for macOS
This file contains hidden or 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 | |
| PROXY_STATE=${1:-on} | |
| PROXY_HOST=<host> | |
| PROXY_PORT=<port> | |
| #export HTTP_PROXY=http://$PROXY_HOST:$PROXY_PORT | |
| #export HTTPS_PROXY=$HTTP_PROXY | |
| INTERFACE=`route -n get default | grep interface | sed "s/.*interface: \(.*\)/\1/"` | |
| if [[ "$INTERFACE" == "" ]]; then | |
| echo could not get default interface | |
| return 1 | |
| fi | |
| NETWORK_SERVICE=`networksetup -listnetworkserviceorder | grep -B1 "$INTERFACE" | head -n 1 | sed "s/([0-9]*) \(.*\)/\1/"` | |
| if [[ "$NETWORK_SERVICE" == "" ]]; then | |
| echo could not get default network service | |
| return 2 | |
| fi | |
| echo network service: $NETWORK_SERVICE | |
| echo proxy: $PROXY_HOST:$PROXY_PORT | |
| echo state: $PROXY_STATE | |
| networksetup -setwebproxy "$NETWORK_SERVICE" $PROXY_HOST $PROXY_PORT | |
| networksetup -setwebproxystate "$NETWORK_SERVICE" $PROXY_STATE | |
| networksetup -setsecurewebproxy "$NETWORK_SERVICE" $PROXY_HOST $PROXY_PORT | |
| networksetup -setsecurewebproxystate "$NETWORK_SERVICE" $PROXY_STATE | |
| networksetup -setproxybypassdomains "$NETWORK_SERVICE" localhost *.local 169.254/16 192.168/16 10/8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment