LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 02-22-2009, 06:32 AM   #1
dwater
Member
 
Registered: Mar 2004
Distribution: redhat 9
Posts: 34

Rep: Reputation: 15
how to set automatic proxy for shell commands?


Hi,

Our company network uses a complicated automatic proxy script to determine if a host is on the internet or the intranet, and to determine which proxy server should be used, if any.

I can set the proxy for commands run from the shell, but is there a way to set it to a script instead of a fixed value - in the same way that a browser can run the javascript function supplied in the proxy.pac file?

Max.
 
Old 02-22-2009, 07:14 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
no, lynx, wget etc... do not support javascript, so can't run proxy.pac. if you want to reimplement this script yourself, then you could easily write a wrapper script around these tools to set it each time.
 
Old 02-22-2009, 07:26 AM   #3
dwater
Member
 
Registered: Mar 2004
Distribution: redhat 9
Posts: 34

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by acid_kewpie View Post
no, lynx, wget etc... do not support javascript, so can't run proxy.pac. if you want to reimplement this script yourself, then you could easily write a wrapper script around these tools to set it each time.
How would I know what host they would be accessing?

The whole problem is that they can access any host and need to run the script for each host they want to access.

Seems like there is no way...I basically need to have them run a command (whether that be javascript or whatever, is irrelevant) instead of just reading an env var. So, instead of :

export http_proxy=myproxy.com:8080
accessVariousHostsOnIntraAndInternet

I would have :

export auto_proxy=findProxy.pl
accessVariousHostsOnIntraAndInternet

Then it has to run each hostname through the script to find out if it's DIRECT and, if not, what proxy to use.

I'm sure there are more efficient methods, around the same principle though.

So, I guess there's nothing like this...and it would need changes to existing software to make it work; in other words, is ain't gonna happen (though it's open source, so I suppose I could...).
 
Old 02-22-2009, 07:45 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
well as above, you should be able to wrap it...

newwget.sh
Code:
URL=$1
HOST=$(echo $1 | cut -d/ -f3)
if [ $HOST -eq google.com ] then
  http_proxy=proxy1:80
else
  http_proxy=proxy2:1234
fi
wget $1
 
Old 02-22-2009, 07:50 AM   #5
dwater
Member
 
Registered: Mar 2004
Distribution: redhat 9
Posts: 34

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by acid_kewpie View Post
well as above, you should be able to wrap it...

newwget.sh
Code:
URL=$1
HOST=$(echo $1 | cut -d/ -f3)
if [ $HOST -eq google.com ] then
  http_proxy=proxy1:80
else
  http_proxy=proxy2:1234
fi
wget $1
That would only work if it's accessing a single host.

For example, what if the host was on the intranet but referenced hosts on the internet, and you wanted to do a wget -r. In this case, wget would have to run the script for every host it needs to access, which, I assume, it doesn't have code for...which, I guess, is the question I'm asking...ie, if there's some mechanism already build into these tools to specify an automatic proxy script.
 
Old 02-22-2009, 07:55 AM   #6
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
I may be wrong with this, since I don't know much about the subject of proxies, but you should be able to use a script to set a variable like this:

export http_proxy=$(findProxy.pl)

Then just make sure the script outputs a string that the variable can use. Whether you can get it do everything you want or not I don't know.
 
Old 02-22-2009, 07:57 AM   #7
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
You already answered it yourself:
Quote:
Originally Posted by dwater View Post
So, I guess there's nothing like this...and it would need changes to existing software to make it work; in other words, is ain't gonna happen (though it's open source, so I suppose I could...).
Go give it your best shot ;-p
 
Old 02-22-2009, 08:09 AM   #8
dwater
Member
 
Registered: Mar 2004
Distribution: redhat 9
Posts: 34

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by David the H. View Post
I may be wrong with this, since I don't know much about the subject of proxies, but you should be able to use a script to set a variable like this:

export http_proxy=$(findProxy.pl)

Then just make sure the script outputs a string that the variable can use. Whether you can get it do everything you want or not I don't know.
I have such a script already :

Code:
#! /usr/bin/perl

use HTTP::ProxyPAC;

my $pac = HTTP::ProxyPAC->new( URI->new("http://proxyconf/proxy.pac") );
my $res = $pac->find_proxy($ARGV[0]);

if ($res->direct) {
    print "Direct\n";
} elsif ($res->proxy) {
    print "Proxy:", $res->proxy('http' => $res->proxy), "\n";
}
...but that only sets it for one host. I'm asking if there's already some mechanism that will cause the script to be run for every host name that a binary wants to access.

It seems this isn't possible. I guess it'd have to be implemented on the network layer somehow...I wonder what this socks thing is about...perhaps that's what I'm after.
 
Old 02-22-2009, 08:18 AM   #9
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
yet again, you've already said this. try a transparent proxy if you want.
 
Old 02-22-2009, 09:29 AM   #10
dwater
Member
 
Registered: Mar 2004
Distribution: redhat 9
Posts: 34

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by acid_kewpie View Post
yet again, you've already said this. try a transparent proxy if you want.
Already said what? You should at least quote what you're referring to - like I did with my previous post, which was in reply to someone else.

In any case, I guess I could indeed run a proxy server only for my local machine and have *it* determine whether to use a DIRECT connection, or use the real proxy server. All traffic would go through my local proxy server. Hrm. I guess this would work...I wonder if there's a setup for squid to do this.

I could either set up all the proxy settings for my local proxy, or I could try to set it up as 'transparent' but would have to be careful it didn't start proxying everyone else's traffic too.

Thanks for the suggestion. I'll look into that further.

(I still wish there were some easier way of doing this though).

Max.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Alias or shell script to confirm 'exit' commands from a shell rose_bud4201 Programming 2 03-08-2006 02:34 PM
Set the path for shell commands??? acidblue Fedora 2 12-23-2005 11:23 PM
Commands automatic during boot leemac Linux - Newbie 4 02-15-2005 01:18 PM
linux shell implementation for a set of commands syeda tabassum Linux - Software 0 11-03-2004 11:53 AM
implementation of linux shell for a set of commands satishkumar LinuxQuestions.org Member Intro 1 10-09-2004 04:28 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 01:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration