#!/usr/bin/perl
#smtp scanner by Tak
use strict;
use warnings;
use Net::Ping;
use Net::Telnet;
print "ip list: "; #asks for ip's
chomp(my $input=<STDIN>); #takes file
#
#if nothing was entered
#
if ($input=~/^$/) {
print "ip range, ex 0.0.0.0-1.1.1.1 :";
chomp($input=<STDIN>);
#idea for most of this ip generator i stole from Asia Pacific Network Information Center (APNIC2)
#
#generateing a log.
$|=1; #pipes become super pipes
print "where to log ip range: ";
chomp(my $log=<STDIN>); #takes a file name to log
open(LOG, '>>', "$log") or die "couldent open $log file\n"; #opens the log file
my @ip0=split(/-/, $input); #seperates ip ranges
my @ip1=split(/\./, $ip0[0]); #seperates numbers
my @ip2=split(/\./, $ip0[$#ip0]);
#complicates loops that generate every ip address inbetween the ranges
for (my $a=$ip1[0]; $a<1+$ip2[0]; $a++) {
for (my $b=$ip1[1]; $b<1+$ip2[1]; $b++) {
for (my $c=$ip1[2]; $c<1+$ip2[2]; $c++) {
for (my $d=$ip1[3]; $d<1+$ip2[3]; $d++) {
print "$a.$b.$c.$d\n";
print LOG "$a.$b.$c.$d\n";
}
}
}
}
close(LOG);
exit 0;
}
open(IP, "$input") or die "couldent open ip file\n"; #opens file
#
my @ip; #all ip addresses
my @liveip; #all working ip addresses
my @deadip; #all dead ip addresses
#
#
foreach(my $line = <IP>) {
$line =~ s/\n//g; #rid of the newline.
push(@ip, "$line");
}
close(IP); #closeing the file
foreach my $ip (@ip) {
#if it exists
if (pingecho($ip, 10)) {
push(@liveip, "$ip");
next;
}
#if its dead
else {
push(@deadip, "$ip");
}
#if nothing is alive
if ($#ip eq $#deadip) {
die "no live hosts\n";
}
}
#wipeing the useless variables
@deadip=();
@ip=();
#we got all the alive ip addresses, now to probe with Telnet for SMTP running!
my @testsmtp; #ip's to be tested for smtp
#makeing the live ip's into telnet objects.
foreach my $ip (@liveip) {
#if no port is there, it gives WTF message. and moves on
my $thing = new Net::Telnet (Host => $ip, Port => '25', Errmode => 'return') or print "WTF?!\n" and next;
#now that we have the objects we can test them.
if ($thing->open()) {
print $thing->host . " has smtp alive\n";
}
}
Refactorings
No refactoring yet !
tak11.myopenid.com
February 2, 2009, February 02, 2009 20:31, permalink
fixed up a little,
#!/usr/bin/perl -w use strict;
#smtp scanner by Tak#
use Net::Ping; use Net::Telnet; local $| = 1; #super pipes my @testsmtp; #ip's to be tested for smtp my @ip; #all ip addresses my @liveip; #all working ip addresses my @deadip; #all dead ip addresses print "ip list: "; chomp( my $input = <STDIN> );
#if nothing was entered #
if ( $input =~ /^$/ ) {
print "ip range, ex 0.0.0.0-1.1.1.1 :";
chomp( $input = <STDIN> );
print "where to log ip range: ";
chomp( my $logIn = <STDIN> ); #takes a file name to log
open( my $log, '>>', "$logIn" )
or die "couldent open $logIn file\n"; #opens the log file
my @ip0 = split( /-/, $input ); #seperates ip ranges
my @ip1 = split( /\./, $ip0[0] ); #seperates numbers
my @ip2 = split( /\./, $ip0[$#ip0] );
#complicates loops that generate every ip address inbetween the ranges
for ( my $a = $ip1[0] ; $a < 1 + $ip2[0] ; $a++ ) {
for ( my $b = $ip1[1] ; $b < 1 + $ip2[1] ; $b++ ) {
for ( my $c = $ip1[2] ; $c < 1 + $ip2[2] ; $c++ ) {
for ( my $d = $ip1[3] ; $d < 1 + $ip2[3] ; $d++ ) {
print "$a.$b.$c.$d\n";
print $log "$a.$b.$c.$d\n";
}
}
}
}
close($log);
exit 0;
}
open( my $ip, "$input" ) or die "couldent open ip file\n"; #opens file
foreach ( my $line = <$ip> ) {
$line =~ s/\n//g; #rid of the newline.
push( @ip, "$line" );
}
close($ip); #closeing the file
foreach my $ip (@ip) {
#if it exists
if ( pingecho( $ip, 10 ) ) {
push( @liveip, "$ip" );
next;
}
#if its dead
else {
push( @deadip, "$ip" );
}
#if nothing is alive
if ( $#ip eq $#deadip ) {
die "no live hosts\n";
}
}
#we got all the alive ip addresses, now to probe with Telnet for SMTP running!#
#makeing the live ip's into telnet objects.
foreach my $ip (@liveip) {
#if no port is there, it gives WTF message. and moves on
my $thing =
new Net::Telnet( Host => $ip, Port => '25', Errmode => 'return' )
or print "WTF?!\n" and next;
#now that we have the objects we can test them.
if ( $thing->open() ) {
print $thing->host . " has smtp alive\n";
}
}
Santa
May 14, 2009, May 14, 2009 17:22, permalink
i cant run this script :S can you help me?
C:\Documents and Settings\Santa\Mis documentos\Smtp>perl scan.pl Can't locate Net/Telnet.pm in @INC (@INC contains: C:/Perl/site/lib C:/Perl/lib .) at scan.pl line 4. BEGIN failed--compilation aborted at scan.pl line 4. C:\Documents and Settings\Santa\Mis documentos\Smtp>
Tak
October 20, 2009, October 20, 2009 22:49, permalink
on windows, open the perl package manager, and install Net::Telnet, on *nix: sudo perl -MCPAN -e shell; install Net::Telnet
lol but this script was coded years ago i'd handle it completely differently
Tak
October 20, 2009, October 20, 2009 22:51, permalink
on windows, open the perl package manager, and install Net::Telnet, on *nix: sudo perl -MCPAN -e shell; install Net::Telnet
lol but this script was coded years ago i'd handle it completely differently
I wrote this a LOONGG time ago, so my style is a bit messey, but im curious, how would anyone improve the actual code