[Mimedefang] MX -> 127.0.0.1

Kevin A. McGrail kmcgrail at pccc.com
Mon Sep 12 14:13:02 EDT 2005


Here is my test stub to add a resolution of the MX records for the domain.
Would appreciate peer review and comments but it looks like a pretty
straightforward test.

#!/usr/bin/perl -w

use strict;
use Net::DNS; #Put in filter_initialize

print &check_primary_mx('kevin.mcgrail at mcgrail.com');

sub check_primary_mx {
  #Based on Idea from Les Miksell
  #KAM 9-12-05
  #takes the sender, extracts the domain name and performs an MX Lookup on
it.
  #if the primary MX exchange eq's 127.0.0.1, then fail.
  #
  #Still returns true on an error because we assume you are testing
resolution with sendmail and
  #some stupid things like bob at donotreply.bigcorporation.com

  my ($sender) = @_;
  my ($res, $packet, @answer, $SenderDomain, $packet2);

  $res = Net::DNS::Resolver->new;

  if (defined ($res)) {
    $res->tcp_timeout(4);              #Number of Seconds before query will
fail
    $res->udp_timeout(4);              #Number of Seconds before query will
fail

    #Strip domain name from an email address
    $SenderDomain = $sender;
    $SenderDomain =~ s/(^<|>$)//g;
    $SenderDomain =~ s/.*\@//g;

    #Perform the DNS Query
    $packet = $res->query($SenderDomain,'MX');

    #Parse the Query
    if (defined ($packet)) {
      if (defined ($packet->answer)) {
        @answer = $packet->answer;
        #print "DEBUG: ".$answer[0]->type." - ".$answer[0]->exchange."\n";
        #Returns exchanges in order of preference.  We only care about the
first.
        if ($answer[0]->type eq "A") {
          if ($answer[0]->exchange eq '127.0.0.1') {
            return (0);
          }
        }
      }
    }
  }

  return (1);
}




More information about the MIMEDefang mailing list