This is the perl script which generates squid “myip acl” and tcp_outgoing_address directives for all the IPs configured on FreeBSD except localhost IP (i.e 127.0.0.1), I have written this script to help my friend configure squid as I describe here.
#!/usr/bin/perl open(IFCONFIG, "ifconfig em0 |"); $count=1; @acls = (); @tcps = (); while (<IFCONFIG>) { if (/inet/) { s/^\s+//; @tokens = split(/ /); if (! ($tokens[1] =~ "127.0.0.1")) { push(@acls, "acl ip$count myip $tokens[1]\n"); push(@tcps, "tcp_outgoing_address $tokens[1] ip$count\n"); $count++; } } } close(IFCONFIG); foreach $acl (@acls) { print $acl; } foreach $tcp (@tcps) { print $tcp; }
Click the “View Plain” link above the code, copy the code from the new window and use it.
I know its not commented but I didn’t had much time because of my Google Summer of Code, and the script is so trivial that I didn’t feel like commenting it.
Tags: FreeBSD, OpenSource, perl, squid
August 11, 2008 at 5:49 am |
Any way you code this up for Linux? π
August 15, 2008 at 7:45 am |
I will on this weekend. π
September 27, 2008 at 5:03 am |
I have a list of IP addresses(outbound) which I need the proxy server randomly select from it. Is this possible?
May 27, 2009 at 5:51 pm |
Just a note to all those trying to use this – the blog software hid a piece of code that makes this sit and do nothing.
The “while () {” line should have something inside the brackets – it’s missing <IFCONFIG>. Add that, and everything should work.
May 29, 2009 at 7:02 am |
Thank you Eli Sand for pointing that out. It has been fixed.
May 27, 2009 at 11:13 pm |
[…] it would go out x.x.x.x and y.y.y.y would go out y.y.y.y and so on. After a little digging we found a neat little script written for FreeBSD that would parse all available IP’s on the box and generate the squid configuration for you, […]
April 22, 2013 at 5:39 am |
Very good article. Welcome to service-labs.com to communicate.