Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
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 :
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...).
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.
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...).
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.
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).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.