42306c1a1e87611519fdf1811ffe2c9c

I wrote this a LOONGG time ago, so my style is a bit messey, but im curious, how would anyone improve the actual code

#!/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 !

42306c1a1e87611519fdf1811ffe2c9c

tak11.myopenid.com

February 2, 2009, February 02, 2009 20:31, permalink

No rating. Login to rate!

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";
    }
}
Bd27789c4d73bf18944c83497da93602

Santa

May 14, 2009, May 14, 2009 17:22, permalink

No rating. Login to rate!

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>
D41d8cd98f00b204e9800998ecf8427e

Tak

October 20, 2009, October 20, 2009 22:49, permalink

No rating. Login to rate!

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

D41d8cd98f00b204e9800998ecf8427e

Tak

October 20, 2009, October 20, 2009 22:51, permalink

No rating. Login to rate!

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

0f0cd7056796fb836103386926b943a0

Wood

March 9, 2010, March 09, 2010 00:55, permalink

No rating. Login to rate!

good

C:\Documents and Settings\Santa\Mis documentos\Smtp>perl scan.pl
09e12ecc7cb2a6db29d5726911c0b8dd

dhan

November 5, 2010, November 05, 2010 02:57, permalink

No rating. Login to rate!

this is can bruteforce password?

A119135e422291947e39dd6cf0855e66

d4rk77

January 7, 2012, January 07, 2012 14:07, permalink

No rating. Login to rate!

ca

A119135e422291947e39dd6cf0855e66

d4rk77

January 7, 2012, January 07, 2012 14:07, permalink

No rating. Login to rate!

ca

Your refactoring





Format Copy from initial code

or Cancel