how to toggle web proxy from commandline

Awesome tips!

I don’t usually use proxy servers. But depending on the network environment, I need to connect proxy servers.

I had been searching for the solution for switching proxy. The more simple or easier, the better.
I tried locamatic, or other softwares. But nothing served well.

Now, that post taught me how to manipulate proxy setting from command line.
That suggests the commads below:

networksetup -setwebproxy Ethernet 80 off
networksetup -setwebproxy Ethernet 80 on proxyuser "p4ssw0rd"
networksetup -setwebproxystate Ethernet off

And then, I added one function to my bashrc for myself.

setPrefProxy() {

    echo "s:$1 p:$2 m:$3"

    if [ ${mode} = "on" ];then
	    networksetup -setwebproxy ${adapter} ${server} ${port} off
	    networksetup -setsecurewebproxy ${adapter} ${server} ${port} off
	    networksetup -setftpproxy ${adapter} ${server} ${port} off
	    networksetup -setwebproxystate ${adapter} off
	    networksetup -setsecurewebproxystate ${adapter} off
	    networksetup -setftpproxystate ${adapter} off


setPrefProxy 8080 Ethernet on[off]
  • You have to input password for modifying configuration.

OK. It may be life-changing.

Leave a Reply

Your email address will not be published. Required fields are marked *