how to you toggle on and off a web proxy in os x from the command line

前端 未结 7 1362
予麋鹿
予麋鹿 2021-01-31 15:45

In OS X, you turn on and off a web proxy from System Preferences > Network > Proxies, by checking Web Proxy (HTTP) and designating the Web Proxy Server etc. and by clicking OK a

7条回答
  •  清酒与你
    2021-01-31 16:15

    I prepared a script named proxy that might help,

    #!/bin/bash
    #
    #
    #   Author: Md. Sazzad Hissain Khan
    #   Date:   8 July, 2017
    #
    #
    
    NETWORK_SERVICE_NAME="Ethernet"
    
    if [ "$#" -ne 1 ]; then
        echo "Argument missing [on/off]"
        exit 0
    fi
    
    if [ $1 == "on" ]; then
        echo "Enabling secure proxy for $NETWORK_SERVICE_NAME"
        networksetup -setsecurewebproxystate "$NETWORK_SERVICE_NAME" on
    elif [ $1 == "off" ]; then
        echo "Disabling secure proxy for $NETWORK_SERVICE_NAME"
        networksetup -setsecurewebproxystate "$NETWORK_SERVICE_NAME" off
    else
        echo "Argument invalid [permitted:on/off]"
    fi
    

    NETWORK_SERVICE_NAME is the name of your active network which you need to configure.

    1. Create proxy file in /usr/local/bin.
    2. Copy above script into proxy.
    3. Set executable permission for the file using sudo chmod 777 proxy .

    How to use:

    proxy on
    proxy off
    

提交回复
热议问题