问题描述
在OS X中,通过检查Web代理(HTTP)并指定Web代理服务器等,然后单击确定",然后单击应用",可以从系统偏好设置">网络">代理"中打开和关闭Web代理.这是太多步骤了.有没有办法从命令行和Shell脚本来完成所有这些工作?
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?
推荐答案
对于未经身份验证的代理(并假设它是您要配置的以太网服务):
For an unauthenticated proxy (and assuming it's the Ethernet service you want to configure):
networksetup -setwebproxy Ethernet proxy.example.net 80 off
用于身份验证:
networksetup -setwebproxy Ethernet proxy.example.net 80 on proxyuser "p4ssw0rd"
并关闭它:
networksetup -setwebproxystate Ethernet off
如果网络服务的名称不只是"Ethernet",则可能需要解析networksetup -listallnetworkservices
或-listnetworkserviceorder
以获得正确的名称.
If the network service isn't named just "Ethernet", you may need to parse networksetup -listallnetworkservices
or -listnetworkserviceorder
to get the correct name.
这篇关于如何从命令行在OS X中打开和关闭Web代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!