Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 and then "Apply". This is way too many steps. Is there a way to do this all from the command line and a shell script?

like image 304
dan Avatar asked Oct 27 '10 02:10

dan


People also ask

How do I find proxy settings on Mac terminal?

This is equivalent to setting the proxy via mac system settings > Network > wi-fi > Advanced > Proxies > Web proxy.


1 Answers

For an unauthenticated proxy (and assuming it's the Ethernet service you want to configure):

networksetup -setwebproxy Ethernet proxy.example.net 80 off 

for authenticated:

networksetup -setwebproxy Ethernet proxy.example.net 80 on proxyuser "p4ssw0rd" 

and to turn it off:

networksetup -setwebproxystate Ethernet off 

If the network service isn't named just "Ethernet", you may need to parse networksetup -listallnetworkservices or -listnetworkserviceorder to get the correct name.

like image 146
Gordon Davisson Avatar answered Oct 07 '22 22:10

Gordon Davisson