#!/usr/bin/perl
# PERL Scripted by bando
# DATE : 20040513
# Mail : bando(at)bando.org
# MSN : bando(at)bando.org
# Mail Server Relay Checker
use Socket;
$NUM = @ARGV;
if ( $NUM != 1 ) {
print "Usage: $0 targethostn";
exit 0;
}
my($host) = $ARGV[0];
my($port) = 25;
&connect($host,$port);
$ip=inet_ntoa($inet_addr);
$buf_size = 1024;
@def_mail = ("bando","bando.org");
%cmd = ("helo"=>"HELO", "rset"=>"RSET" ,"from"=>"MAIL FROM:", "to"=>"RCPT TO:");
@relay_from = ("<>", "<$def_mail[0]>", "<$def_mail[0]@>", "<$def_mail[0]@$def_mail[1]>", "<$def_mail[0]@[$ip]>");
@relay_to = ("<$def_mail[0]@$def_mail[1]>", "<"$def_mail[0]@$def_mail[1]">", "<$def_mail[0]@$def_mail[1]@>", "<$def_mail[0]%$def_mail[1]>", "<"$def_mail[0]%$def_mail[1]">", "<$def_mail[0]@$def_mail[1]@[$ip]>", "<"$def_mail[0]@$def_mail[1]"@[$ip]>", "<@[$ip]:$def_mail[0]@$def_mail[1]>", "<@:$def_mail[0]@$def_mail[1]>", "<$def_mail[1]!$def_mail[0]>", "<$def_mail[1]!$def_mail[0]@>", "<$def_mail[1]!$def_mail[0]@[$ip]>");
$pat_num = $#relay_from + $#relay_to + 1;
$relay_ok = 0;
recv(SOCK,$recv,$buf_size,$flag);
print "<<< $recvn";
print ">>> $cmd{helo} $def_mail[1]n";
defined(send(SOCK,"$cmd{helo} $def_mail[1]rn",$flag)) or die "SEND ERROR : $cmd{helo}n";
recv(SOCK,$recv,$buf_size,$flag);
print "<<< $recvn";
foreach(0..$pat_num) {
print "nRELAY TEST : ",($_ + 1);
if($_ > $#relay_from) {
$relay_from_send=$relay_from[$#relay_from];
$relay_to_send=$relay_to[$_ - $#relay_from - 1];
}
else {
$relay_from_send=$relay_from[$_];
$relay_to_send=$relay_to[0];
}
my($send_from) = $cmd{from} . $relay_from_send;
my($send_to) = $cmd{to} . $relay_to_send;
&send_recv($send_from,$send_to);
}
print "nOK RELAY : $relay_okn";
close(SOCK);
sub connect {
my($host) = $_[0];
my($port) = $_[1];
$flag=0;
my($timeout) = 5;
$inet_addr=inet_aton($host);
$paddr=sockaddr_in($port,$inet_addr);
socket(SOCK,PF_INET,SOCK_STREAM,getprotobyname('tcp'));
eval {
local $SIG{ALRM}= sub { die "timeoutn" };
alarm($timeout);
connect(SOCK,$paddr);
alarm(0);
};
if($@) {
if($@ =~ /timeout/i) {
print "ERROR : CONNECTING TIMEOUT!n";
}
else {
print "ERROR : $@n";
}
exit 1;
}
}
sub send_recv {
$ch_from=$_[0];
$ch_to=$_[1];
print "n>>> $cmd{rset}n";
defined(send(SOCK,"$cmd{rset}rn",$flag)) or die "SEND ERROR : $cmd{rset}n";
recv(SOCK,$recv,$buf_size,$flag);
print "<<< $recv";
$ch_from =~ s/</</g;
$ch_from =~ s/>/>/g;
print ">>> $ch_fromn";
defined(send(SOCK,"$_[0]rn",$flag)) or die "SEND ERROR : $_[0]n";
recv(SOCK,$recv,$buf_size,$flag);
$recv =~ s/</</g;
$recv =~ s/>/>/g;
print "<<< $recv";
if($recv =~ /^250/) {
$ch_to =~ s/</</g;
$ch_to =~ s/>/>/g;
print ">>> $ch_ton";
defined(send(SOCK,"$_[1]rn",$flag)) or die "SEND ERROR : $_[1]n";
recv(SOCK,$recv,$buf_size,$flag);
$recv =~ s/</</g;
$recv =~ s/>/>/g;
print "<<< $recv";
if($recv =~ /^250/) {
print "RESULT : RELAY YESn";
$relay_ok++;
}
else {
print "RESULT : RELAY NOn";
}
}
else {
print "RESULT : RELAY NOn";
}
}
# PERL Scripted by bando
# DATE : 20040513
# Mail : bando(at)bando.org
# MSN : bando(at)bando.org
# Mail Server Relay Checker
use Socket;
$NUM = @ARGV;
if ( $NUM != 1 ) {
print "Usage: $0 targethostn";
exit 0;
}
my($host) = $ARGV[0];
my($port) = 25;
&connect($host,$port);
$ip=inet_ntoa($inet_addr);
$buf_size = 1024;
@def_mail = ("bando","bando.org");
%cmd = ("helo"=>"HELO", "rset"=>"RSET" ,"from"=>"MAIL FROM:", "to"=>"RCPT TO:");
@relay_from = ("<>", "<$def_mail[0]>", "<$def_mail[0]@>", "<$def_mail[0]@$def_mail[1]>", "<$def_mail[0]@[$ip]>");
@relay_to = ("<$def_mail[0]@$def_mail[1]>", "<"$def_mail[0]@$def_mail[1]">", "<$def_mail[0]@$def_mail[1]@>", "<$def_mail[0]%$def_mail[1]>", "<"$def_mail[0]%$def_mail[1]">", "<$def_mail[0]@$def_mail[1]@[$ip]>", "<"$def_mail[0]@$def_mail[1]"@[$ip]>", "<@[$ip]:$def_mail[0]@$def_mail[1]>", "<@:$def_mail[0]@$def_mail[1]>", "<$def_mail[1]!$def_mail[0]>", "<$def_mail[1]!$def_mail[0]@>", "<$def_mail[1]!$def_mail[0]@[$ip]>");
$pat_num = $#relay_from + $#relay_to + 1;
$relay_ok = 0;
recv(SOCK,$recv,$buf_size,$flag);
print "<<< $recvn";
print ">>> $cmd{helo} $def_mail[1]n";
defined(send(SOCK,"$cmd{helo} $def_mail[1]rn",$flag)) or die "SEND ERROR : $cmd{helo}n";
recv(SOCK,$recv,$buf_size,$flag);
print "<<< $recvn";
foreach(0..$pat_num) {
print "nRELAY TEST : ",($_ + 1);
if($_ > $#relay_from) {
$relay_from_send=$relay_from[$#relay_from];
$relay_to_send=$relay_to[$_ - $#relay_from - 1];
}
else {
$relay_from_send=$relay_from[$_];
$relay_to_send=$relay_to[0];
}
my($send_from) = $cmd{from} . $relay_from_send;
my($send_to) = $cmd{to} . $relay_to_send;
&send_recv($send_from,$send_to);
}
print "nOK RELAY : $relay_okn";
close(SOCK);
sub connect {
my($host) = $_[0];
my($port) = $_[1];
$flag=0;
my($timeout) = 5;
$inet_addr=inet_aton($host);
$paddr=sockaddr_in($port,$inet_addr);
socket(SOCK,PF_INET,SOCK_STREAM,getprotobyname('tcp'));
eval {
local $SIG{ALRM}= sub { die "timeoutn" };
alarm($timeout);
connect(SOCK,$paddr);
alarm(0);
};
if($@) {
if($@ =~ /timeout/i) {
print "ERROR : CONNECTING TIMEOUT!n";
}
else {
print "ERROR : $@n";
}
exit 1;
}
}
sub send_recv {
$ch_from=$_[0];
$ch_to=$_[1];
print "n>>> $cmd{rset}n";
defined(send(SOCK,"$cmd{rset}rn",$flag)) or die "SEND ERROR : $cmd{rset}n";
recv(SOCK,$recv,$buf_size,$flag);
print "<<< $recv";
$ch_from =~ s/</</g;
$ch_from =~ s/>/>/g;
print ">>> $ch_fromn";
defined(send(SOCK,"$_[0]rn",$flag)) or die "SEND ERROR : $_[0]n";
recv(SOCK,$recv,$buf_size,$flag);
$recv =~ s/</</g;
$recv =~ s/>/>/g;
print "<<< $recv";
if($recv =~ /^250/) {
$ch_to =~ s/</</g;
$ch_to =~ s/>/>/g;
print ">>> $ch_ton";
defined(send(SOCK,"$_[1]rn",$flag)) or die "SEND ERROR : $_[1]n";
recv(SOCK,$recv,$buf_size,$flag);
$recv =~ s/</</g;
$recv =~ s/>/>/g;
print "<<< $recv";
if($recv =~ /^250/) {
print "RESULT : RELAY YESn";
$relay_ok++;
}
else {
print "RESULT : RELAY NOn";
}
}
else {
print "RESULT : RELAY NOn";
}
}
출처 : http://ttongfly.net/zbxe/?mid=script&document_srl=43598