Generating squid “myip acl” and tcp_outgoing_address for all your IPs on FreeBSD

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, I have written this script to help my friend configure squid as I describe here.

open(IFCONFIG, "ifconfig em0 |");
@acls = ();
@tcps = ();
while (<IFCONFIG>) {
  if (/inet/) {
    @tokens = split(/ /);
    if (! ($tokens[1] =~ "")) {
       push(@acls, "acl ip$count myip $tokens[1]\n");
       push(@tcps, "tcp_outgoing_address $tokens[1] ip$count\n");
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: , , ,

7 Responses to “Generating squid “myip acl” and tcp_outgoing_address for all your IPs on FreeBSD”

  1. Jay Says:

    Any way you code this up for Linux? πŸ™‚

  2. Hameedullah Khan Says:

    I will on this weekend. πŸ™‚

  3. Chris Says:

    I have a list of IP addresses(outbound) which I need the proxy server randomly select from it. Is this possible?

  4. Eli Sand Says:

    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.

  5. Listing all IP’s on a Linux Server when Setting up a Squid Proxy made easy with this script | Says:

    […] 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, […]

  6. Service-labs Says:

    Very good article. Welcome to to communicate.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: