Date: 2005-12-02 22:46
Views:0
很久以前TNT帮我写了个扫exchange的东西,呵呵,没经过他同意我还是PUB一下 :)
#!/usr/bin/perl # cnhackTNT [AT] perlchina.org # http://atzone.ipchina.org # Welcome to http://www.perlchina.org # ugly code just for test # for baozi :-)
use Socket; use Parallel::ForkManager;
my $timeout = 10; #超时设定(秒) my $child_num = 20; #进程数设定 my $chunk = $ARGV[1];
usage() if ( @ARGV != 2 );
$SIG{ALRM} = sub { warn "*** handling $ip timeout! ***n"; exit 0 };
open( FH, $ARGV[0] ) or die "Can't open file $ARGV[0]!n"; @ip = <FH>; close FH;
open( FH, '>result.txt' ) or die "Can't open file:$!n";
my $pm = new Parallel::ForkManager($child_num);
for my $ip (@ip) { $pm->start and next; chomp $ip; ehlo($ip); $pm->finish; }
$pm->wait_all_children; close FH;
sub ehlo { our $ip = shift; alarm(5); socket( SOCK, PF_INET, SOCK_STREAM, ( getprotobyname('tcp') )[0] ) or warn "Can not create socket:$!n"; if ( connect( SOCK, sockaddr_in( 25, inet_aton($ip) ) ) ) { print "I am dealing with $ipn"; my $handle = select SOCK; $|++; print "ehlorn"; select $handle; while (<SOCK>) {
#print; if (/$chunk/) { print "### Found $chunk on $ipn"; print FH "$ipn"; } last if (/250 OK/); } print SOCK "QUITrn"; alarm(0); exit 0; } }
sub usage { print <<EOF; n I need TWO arguments !! --------------------------------------------- usage: perl $0 IP_LIST_FILE Pattern --------------------------------------------- Welcome to http://www.perlchina.org n EOF exit; }
|