Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Set proxy environment variables automatically UNIX
I am a heavy Terminal.app user, and happen to use tools like wget a lot. However, when I am in a network environment requiring a proxy server, I have to set the usual environment variables http_proxy, ftp_proxy, etc by hand. Finally, after years of typing, I wrote a small utility called setproxy that would generate these statements for me. After downloading, install using
make && make install
and then use setproxy like this:
eval `setproxy`
when using a sh-like shell or
eval `setproxy -t`
when using a csh-like shell. You can put this line in you shell-profile file so it gets executed automatically on terminal startup.
    •    
  • Currently 2.50 / 5
  You rated: 1 / 5 (4 votes cast)
 
[13,830 views]  

Set proxy environment variables automatically | 3 comments | Create New Account
Click here to return to the 'Set proxy environment variables automatically' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Set proxy environment variables automatically
Authored by: fds on Jan 13, '04 02:28:24PM
Thanks, just what the doctor ordered! I've been thinking of writing something like this ever since I got my Mac (still less than a year ago.). :)
My gratitude for saving me the time to look up the information.

I modified the output ever so slightly to fit my needs better to


	if (GetHTTPProxySetting(host, sizeof(host), &port))
		printf("http_proxy=http://%s:%u/ ", host, port);
	if (GetHTTPSProxySetting(host, sizeof(host), &port))
		printf("https_proxy=http://%s:%u/ ", host, port);
	if (GetFTPProxySetting(host, sizeof(host), &port))
		printf("ftp_proxy=http://%s:%u/ ", host, port);
Then I just alias my wget etc. commands like this:

alias wget="`setproxy` wget"
So the proxy settings get refreshed automatically when I start a new wget process plus it only gets set for that specific process so there's no need for the unsets.

I use bash, I'm not sure if something like this is feasible with other shells.

Now we just need to figure out how to take into account the proxy exclusion list...

[ Reply to This | # ]

Set proxy environment variables automatically
Authored by: blalor on Jan 13, '04 03:39:49PM
actually, that alias doesn't work. It gets expanded when it is declared, instead of at excecution time. Try this, with the original setproxy: in ~/.bashrc:

my_wget() {
    eval $(setproxy)
    wget $*
}

alias wget='my_wget'


[ Reply to This | # ]
Set proxy environment variables automatically
Authored by: conall on Sep 03, '04 08:48:05PM

The exclusion list problem is easily solved, simply set the $no_proxy enviromental variable, eg
export no_proxy=.domain.com.


It works in bash at least, should be shell independant, since programs like curl and wget check for such variables...



[ Reply to This | # ]