Mail-Address Check.pl

Aus SiWiki
Wechseln zu: Navigation, Suche
#!/usr/bin/perl
 
# Copyright (c) 2015 by Peter_Siegrist(SystemLoesungen)  (PSS @ ZweierNet.ch)
# pss.ZweierNet.ch
#
# This program is absolutely free software. 
# Use it as you like but don't point the finger of blame to me.
#
 
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;