Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Is it possible to get the proxy address that my system is currently using in order to populate HTTP_PROXY variable from command line ?

I would like a command so that I could set it in my .bashrc file.

complete solution for me was to update my .bashrc file with this

function http_proxy { 
    export http_proxy=`networksetup -getwebproxy Wi-Fi  | head -3 | tail -2  | cut -f2 -d' ' | sed 'N;s/\n/:/'|grep -v ':0'`
}
alias homen="networksetup -setwebproxy Wi-Fi '' ;http_proxy"
alias ofcn="networksetup -setwebproxy Wi-Fi proxy.examp.com 8080;http_proxy"
http_proxy
share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

Either get ProxyConf, which does exactly this.

Or retrieve the web proxy with networksetup -getwebproxy Ethernet (replace Ethernet with the one you're using from networksetup -listallnetworkservices), then format the output into HTTP_PROXY format:

$ networksetup -getwebproxy Ethernet | awk '/Server:/ {host=$2} /Port: / {port=$2} END { printf "http://%s:%s", host, port}'
http://127.0.0.1:8228

If your network services (Ethernet, Wifi, etc.) vary or you use multiple at the same time, you may need to get a little more elaborate to figure out which one is being used. man networksetup and man ifconfig should have everything you need if you want to go there.

Formerly there was also scselect, but networksetup incorporates all of it's functionality.

share|improve this answer
1  
Updated question with the approach I took. Thanks Ingmar ! –  Sairam Sep 2 '11 at 5:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.