用Perl語言進(jìn)行Socket編程之4
發(fā)表時(shí)間:2024-06-11 來源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
[摘要]這是源碼:#!/usr/bin/perl # test.pl #Author homepage: http://spot.126.com use strict; use Socket; my $pop3server = "263.net"; my $port = 110; $ ...
這是源碼:
#!/usr/bin/perl
# test.pl
#Author homepage: http://spot.126.com
use strict;
use Socket;
my $pop3server = "263.net";
my $port = 110;
$ =1;
print "Content-type: text/html
";
print "POP3
";
print "
";
my ($a,$name,$aliases,$proto,$type,$len,$thataddr,$thisaddr,$i);
my $AF_INET = 2;
my $SOCK_STREAM = 1;
my $sockaddr = "S n a4 x8";
($name,$aliases,$proto) = getprotobyname("tcp");
($name,$aliases,$port) = getservbyname($port,"tcp")
unless $port =~ /^d+$/;;
($name,$aliases,$type,$len,$thataddr) = gethostbyname($pop3server);
my $this = pack($sockaddr, $AF_INET, 12345, $thisaddr);
my $that = pack($sockaddr, $AF_INET, $port, $thataddr);
my $mysocket = socket(S, $AF_INET, $SOCK_STREAM, $proto);
if ($mysocket)
{
}
else
{
print "不能打開socket: $!";
exit(0);
}
my $mybind = bind(S, $this);
if ($mybind)
{
}
else
{
print "無法綁定!: $!";
exit(0);
}
my $myconnect = connect(S,$that);
if ($myconnect)
{
}
else
{
print "連接錯(cuò)誤: $!";
exit(0);
}
my $BUF = "";
my $SenderIP = recv(S, $BUF, 596,0);
if ($SenderIP)
{
}
else
{
print "接收錯(cuò)誤: $!";
exit(0);
}
if (substr($BUF,0,3) eq "+OK")
{
}
else
{
print "POP3服務(wù)器出錯(cuò)!
";
exit(0);
}
my $BUFFER = "USER zhangsan";
$BUFFER .= chr(13);
$BUFFER .= chr(10);
my $SENVAL = send(S, $BUFFER,0);
if ($SENVAL)
{
}
else
{
print "發(fā)送錯(cuò)誤: $!";
exit(0);
}
my $BUF = "";
my $SenderIP = recv(S, $BUF, 4096,0);
if ($SenderIP)
{
}
else
{
print "接收錯(cuò)誤: $!";
exit(0);
}
if (substr($BUF,0,3) eq "+OK")
{
}
else
{
print "無此帳號(hào)!
";
exit(0);
}
$BUFFER = "PASS 12345678";
$BUFFER .= chr(13);
$BUFFER .= chr(10);
my $SENVAL = send(S, $BUFFER,0);
if ($SENVAL)
{
}
else
{
print "發(fā)送錯(cuò)誤: $!";
exit(0);
}
$BUF = "";
my $SenderIP = recv(S, $BUF, 196, 0);
if ($SenderIP)
{
}
else
{
print "接收錯(cuò)誤: $!";
exit(0);
}
if (substr($BUF,0,3) eq "+OK")
{
}
else
{
print "密碼錯(cuò)誤!
";
exit(0);
}
print密碼是正確的!
本程序版權(quán)歸菜瓜樂園
EOF
exit(0);