文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>测试邮箱的perl脚本

测试邮箱的perl脚本

时间:2008-08-17  来源:mars531706

#!/usr/bin/perl -w
# Check the mail server status
# Author Mars Huang
use strict;
use Socket;
use Time::HiRes qw( usleep ualarm gettimeofday tv_interval nanosleep
                      clock_gettime clock_getres clock_nanosleep clock
                      stat );

if($#ARGV != 1)
{
    print "Usage: programe userName password\n";
    exit;
}

my $userName=shift;
my $password=shift;
my $PF_INET=2;
my $SOCK_DGRAM=1;
my $port = 110;
my $proto = getprotobyname("tcp");
my $address = pack('SnC4x8',$PF_INET,$port,218,204,249,6);
my $buffer;
my $errorMessage;
my($startTime,$startMs,$endTime,$endMs,$spentTime);
my $success = 0;
socket(SOCKET,$PF_INET,$SOCK_DGRAM,$proto) or die "Can't build a socket";

# Begin test
($startTime,$startMs) = gettimeofday;
connect(SOCKET,$address) or die "Can't connect to server";
$buffer=<SOCKET>;
if($buffer !~ /^\+OK/)
{
     print "ERROR protocol error during welcome";
}

# Check the username
send(SOCKET,"user $userName\r\n",0);
$buffer=<SOCKET>;
if($buffer !~ /^\+[oOkK]/)
{
    print "ERROR useraname ";
    exit;
}

# Check the password
send(SOCKET,"pass $password\r\n",0);
$buffer=<SOCKET>;
if($buffer !~ /^\+[oOkK]/)
{
    print "ERROR password error \n";
    exit;
}

# Check the list
send(SOCKET,"list\r\n",0);
$buffer=<SOCKET>;
if($buffer !~ /^\+[oOkK]/)
{
    print "ERROR list\n";
    exit;
}

# Read the mail
send(SOCKET,"retr 1\r\n",0);
while(<SOCKET>)
{
    if(m/\-ERR/)
    {
        $errorMessage = $_;
        print "ERROR: ",$errorMessage;
        exit;
    }
    if(m/^\.\r\n$/)
    {
        $success =1;
        last;
    }
}

# Send the quit
send(SOCKET,"quit\r\n",0);
$buffer=<SOCKET>;
if($buffer !~ /^\+OK/)
{
    print "ERROR: ",$buffer;
    exit;
}

($endTime,$endMs) = gettimeofday;
$spentTime = ($endTime - $startTime) + ($endMs - $startMs) / 1000000;
if($success == 1)
{
    printf("OK ! Time used : %.3f sec \n", $spentTime);
}
else
{
    print "ERROR at  retr. \n";
}
相关阅读 更多 +
排行榜 更多 +
别惹神枪手安卓版

别惹神枪手安卓版

冒险解谜 下载
坦克战争世界

坦克战争世界

模拟经营 下载
丛林反击战

丛林反击战

飞行射击 下载