[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Postfix randomizing outgoing IP using [SOLVED]



I wrote the perl script again. The new script contains my own ip address range check. if the IP of the domain is in my IP range it prints "200 dovecot:" message.

#!/usr/bin/perl -w
# author: Hari Hendaryanto <hari.h -at- csmcom.com>

#use strict;
use warnings;
use Sys::Syslog qw(:DEFAULT setlogsock);
use Net::DNS;
use Net::CIDR;
use Net::CIDR ':all';
my $dns = new Net::DNS::Resolver;
#
# our transports array, we will define this in master.cf as transport services
#
our @cidr_list;
@cidr_list=Net::CIDR::cidradd("1.1.1.1/24");
@cidr_list=Net::CIDR::cidradd("2.2.2.2/24", @cidr_list);

our @array = (
'rotate1:',
'rotate2:',
'rotate3:'
);

#
# Initalize and open syslog.
#
openlog('postfix/randomizer','pid','mail');

#
# Autoflush standard output.
#
select STDOUT; $|++;
while (<>) {
        chomp;
        # randomizing transports array
        my $random_smtp = int(rand(scalar(@array)));
        if (/^get\s(.+)$/i) {
        my $local_domain = $1;
                $local_domain =~ s/.*\@//i;
            my $prefix = 'mx1.';
            my $mx = $dns->query( $prefix.$local_domain, 'A' );
            my $is_local = 0;
foreach my $rr ($mx->answer) { #maybe it returns multiple results
            if(Net::CIDR::cidrlookup($rr->address, @cidr_list)==1){
            $is_local = 1;
        }

        if ($is_local == 1){
            print "200 dovecot:\n";
            syslog("info","Using: %s Transport Service", $local_domain);
        } else {
                        print "200 $array[$random_smtp]\n";
syslog("info","Using: %s Transport Service", $random_smtp);
                }
                next;
        }

    print "200 smtp:";
}


--
M.Atıf CEYLAN
Yurdum Yazılım


Reply to: