Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 8080;http_proxy"
share|improve this question
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}'

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
Updated question with the approach I took. Thanks Ingmar ! – Sairam Sep 2 '11 at 5:42

Your Answer


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.