Mail-Address Check.pl

Aus Si:Wiki von Siegrist SystemLösungen - Informatik und Rezepte
Wechseln zu: Navigation, Suche
#!/usr/bin/perl
 
use strict;
use IO::Socket::INET;
 
sub TRUE { 1; }
sub FALSE { 0; }
 
if ( ($#ARGV + 1) < 3 ) {
	print "Usage: $0  < mailserver-to-check-for > < port-on-server-25-or-587 > < email-adress-to-check > \n";
	exit;
}
my $server = shift;
my $port = shift;
my $address_to_check = shift;
my $answer = "";
my $SOCKET = IO::Socket::INET->new(
        PeerAddr => "$server",
        PeerPort => "$port",
        Proto   => 'tcp') || die "Error in create socket!: $!";
 
<$SOCKET>;
print $SOCKET "HELO xy\n";
<$SOCKET>;
print $SOCKET "RSET\n";
<$SOCKET>;
print $SOCKET "MAIL FROM: addrecheck\@example.org\n";
<$SOCKET>;
$answer = "";
print $SOCKET "RCPT TO: $address_to_check\n";
$answer = <$SOCKET>;
print "Answer: $answer\n";
 
close $SOCKET;
 
exit FALSE if $answer !~ m/\s+ok/i;
exit TRUE;