Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5351650
  • 博文数量: 1144
  • 博客积分: 11974
  • 博客等级: 上将
  • 技术积分: 12312
  • 用 户 组: 普通用户
  • 注册时间: 2005-04-13 20:06
文章存档

2017年(2)

2016年(14)

2015年(10)

2014年(28)

2013年(23)

2012年(29)

2011年(53)

2010年(86)

2009年(83)

2008年(43)

2007年(153)

2006年(575)

2005年(45)

分类:

2008-09-21 19:14:04

#!/usr/bin/perl -w


use Socket;
use strict;


my($mailTo) = 'dave@cs.cf.ac.uk';


my($mailServer) = 'mailhost2.cs.cf.ac.uk';


my($mailFrom) = 'dave@cs.cf.ac.uk';
my($realName) = "Ralph Martin";
my($subject) = 'Test';
my($body) = "Test Line One.nTest Line Two.n";


$main::SIG{'INT'} = 'closeSocket';


my($proto) = getprotobyname("tcp") || 6;
my($port) = getservbyname("SMTP", "tcp") || 25;
my($serverAddr) = (gethostbyname($mailServer))[4];


if (! defined($length)) {


die('gethostbyname failed.');
}


socket(SMTP, AF_INET(), SOCK_STREAM(), $proto)
or die("socket: $!");


$packFormat = 'S n a4 x8'; # Windows 95, SunOs 4.1+
#$packFormat = 'S n c4 x8'; # SunOs 5.4+ (Solaris 2)


connect(SMTP, pack($packFormat, AF_INET(), $port, $serverAddr))
or die("connect: $!");


select(SMTP); $| = 1; select(STDOUT); # use unbuffemiles i/o.


{
my($inpBuf) = '';


recv(SMTP, $inpBuf, 200, 0);
recv(SMTP, $inpBuf, 200, 0);
}


sendSMTP(1, "HELOn");
sendSMTP(1, "MAIL From: <$mailFrom>n");
sendSMTP(1, "RCPT To: <$mailTo>n");
sendSMTP(1, "DATAn");


send(SMTP, "From: $realNamen", 0);
send(SMTP, "Subject: $subjectn", 0);
send(SMTP, $body, 0);


sendSMTP(1, "rn.rn");
sendSMTP(1, "QUITn");


close(SMTP);


sub closeSocket { # close smtp socket on error
close(SMTP);
die("SMTP socket closed due to SIGINTn");
}


sub sendSMTP {
my($debug) = shift;
my($buffer) = @_;


print STDERR ("> $buffer") if $debug;
send(SMTP, $buffer, 0);


recv(SMTP, $buffer, 200, 0);
print STDERR ("< $buffer") if $debug;


return( (split(/ /, $buffer))[0] );
}

This program displays:

> HELO
< 250 sentinel.cs.cf.ac.uk Hello dave@miles.cs.cf.ac.uk
[207.3.100.120], pleased to meet you
> MAIL From:
< 250 ... Sender ok
> RCPT To:
< 250 ... Recipient ok
> DATA
< 354 Enter mail, end with "." on a line by itself
>
.
< 250 TAA12656 Message accepted for delivery
> QUIT
< 221 sentinel.cs.cf.ac.uk closing connection

The lines in bold are the commands that were sent to the server. The body of the letter is not shown in the output.

阅读(1319) | 评论(0) | 转发(0) |
0

上一篇:perl 后门

下一篇:DNS Verification

给主人留下些什么吧!~~