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

前端 未结 7 1382
予麋鹿
予麋鹿 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:26

    To just toggle on/off my proxies in OSX Mavericks, I set up this script. Note that this example just affects my wi-fi adapter. I am toggling on/off the web, streaming, and SOCKS proxies all at once. You could set the proxy address as well, per Gordon's example, but I already had this saved through the System Preferences > Network > Proxies GUI.

    BASH Script, saved as prox.sh:

    #!/bin/bash
    
    e=$(networksetup -getwebproxy wi-fi | grep "No")
    
    if [ -n "$e" ]; then
      echo "Turning on proxy"
      sudo networksetup -setstreamingproxystate wi-fi on
      sudo networksetup -setsocksfirewallproxystate wi-fi on
      sudo networksetup -setwebproxystate wi-fi on
    else
      echo "Turning off proxy"
      sudo networksetup -setstreamingproxystate wi-fi off
      sudo networksetup -setsocksfirewallproxystate wi-fi off
      sudo networksetup -setwebproxystate wi-fi off
    fi
    

    Then symlink the script on the command line:

    ln -s /Script/Location/prox.sh prox-toggle
    

    Now you can toggle the proxies on/off at the command line:

    bash prox-toggle
    

提交回复
热议问题