
multi thread in perl,Scalars leaked is occured?
I’m a network administrator,and must scan my office network every week.I must scan ftp weak password and ssh password and resolve hostname,so do this script.But Scalars leaked is occured.Could you help me?
Code is too long to post here,I will post it as a answer.
faint,I can’t answer my own question.this is my friend’s ID.
#!/usr/bin/perl -w
use strict;
use threads;
use Net::IP;
use Net::FTP;
use Net::SSH::Perl;
########################################################################
# global variable
########################################################################
my @users = ( ‘root’,'user’,'ftp’ );
my @pwds = ( ’123′, ’12345′, ‘ftp’, ‘root’ );
my $if_scan_ftp = ‘false’;
my $if_scan_ssh = ‘false’;
my @ip_list;
my $max_thread = 30;
my $current_thread = 0;
my @thread_array;
my $time_out = 3;
########################################################################
# sub function
########################################################################
sub Usage
{
print “nTest to scan weak password,code by xingguo 060909n”;
print “Usage: scan_pass.pl
# check arguments
if( @ARGV < 3 )
{
Usage( );
exit 0;
}
if( ( ($ARGV[0] ne '-ip') && ($ARGV[0] ne '-list') ) )
{
Usage( );
exit 0;
}
foreach my $arg( @ARGV )
{
if( $arg eq '-ftp' )
{
$if_scan_ftp = 'true';
}
if( $arg eq '-ssh' )
{
$if_scan_ssh = 'true';
}
}
print "Load IP list.....n";
MakeIPList( );
print "Starting scan.....n";
foreach my $remote_host( @ip_list )
{
if( $current_thread > $max_thread )
{
foreach my $thread( @thread_array )
{
$thread -> join( );
}
$current_thread = 0;
}
$thread_array[$current_thread] = threads -> new( &ScanHost, $remote_host );
$current_thread ++;
print “Now thread is $current_threadn”;
}
sub ScanHost
{
my $remote_host = shift;
if( $if_scan_ftp eq ‘true’ )
{
foreach my $user ( @users )
{
foreach my $pass( @pwds )
{
my $ftp = Net::FTP -> new( $remote_host, Timeout => $time_out );
if( ! $ftp )
{
return -1;
}
my $flag = $ftp -> login( $user, $pass );
if( $flag )
{
print “Found ftp account from $remote_host: $user/$passn”;
}
}
}
print “Scan ftp account from $remote_host done.n”;
return 0;
}
}
sub MakeIPList
{
my $start_ip;
my $end_ip;
my $string_ip;
if( $ARGV[0] eq ‘-ip’ )
{
$start_ip = $ARGV[1];
$end_ip = $ARGV[2];
for( my $index = IntIP($start_ip); $index <= IntIP($end_ip); $index ++ )
{
$string_ip = StringIP( $index );
push( @ip_list, $string_ip );
}
}
elsif( $ARGV[0] eq '-list' )
{
open( RH, "<$ARGV[1]" ) || die "Open $ARGV[1] error....n";
while( my $line =
{
chomp( $line );
if( $line =~ /^(d+.d+.d+.d+)-(d+.d+.d+.d+)+$/ )
{
$start_ip = $1;
$end_ip = $2;
for( my $index = IntIP($start_ip); $index <= IntIP($end_ip); $index ++ )
{
$string_ip = StringIP( $index );
push( @ip_list, $string_ip );
}
}
elsif( $line =~ /^d+.d+.d+.d+$/ )
{
push( @ip_list, $line );
}
}
}
}
#sub CheckPort
#{
# my $host = shift;
# my $port = shift;
#
# my $sock = IO::Socket::INET->new( PeerAddr => $host,
# PeerPort => $port,
# Timeout => $time_out );
#
# $sock -> close();
#
# return $sock;
#}
sub IntIP
{
my $ip = new Net::IP( shift );
return $ip -> intip( );
}
sub StringIP
{
my $in = shift;
my $oct = sprintf(“%o”,$in);
$in=~ s/^0//;
my %scale=( ’0′=>’000′,
’1′=>’001′,
’2′=>’010′,
’3′=>’011′,
’4′=>’100′,
’5′=>’101′,
’6′=>’110′,
’7′=>’111′
);
my @scale = split( “”, $oct );
my $bin = “”;
foreach( @scale )
{
$bin .= $scale{$_};
}
if( length($bin) < 32 )
{
my $less = 32 - length($bin);
my $before = '0' x $less;
$bin = $before.$bin;
goto strip;
}
while( length($bin) > 32 )
{
my @bin_array = split( “”, $bin );
my $index;
my $number = @bin_array;
if( $bin_array[0] == 0 )
{
$bin = “”;
for( $index = 1; $index <= $number; $index ++ )
{
$bin = $bin.$bin_array[$index];
}
}
else
{
last;
}
}
goto strip;
strip:
my $bin_ip1 = substr( $bin, 0, 8 );
my $bin_ip2 = substr( $bin, 8, 8 );
my $bin_ip3 = substr( $bin, 16, 8 );
my $bin_ip4 = substr( $bin, 24, 8 );
my $string_ip = b2d( $bin_ip1 ).".".b2d( $bin_ip2 ).".".b2d( $bin_ip3 ).".".b2d( $bin_ip4 );
return $string_ip;
}
sub b2o{
my $in=shift;
my %scale=( '000'=>’0′,
’001′=>’1′,
’010′=>’2′,
’011′=>’3′,
’100′=>’4′,
’101′=>’5′,
’110′=>’6′,
’111′=>’7′
);
my $out=”";
my $tmp=”";
my $exitFlag=0;
while(!$exitFlag){
$tmp=substr($in,-3,3);
if(length($tmp)<2){
$tmp='00'.$tmp;
$exitFlag=1;
}
elsif(length($tmp)<3){
$tmp='0'.$tmp;
$exitFlag=1;
}
$out=$scale{$tmp}.$out;
$in=substr($in,0,-3);
}
$out;
}
sub o2d{
my $in=shift;
$in=~ s/^0//;$in=~s/^(d)/0$1/;
my $out;
eval "$out=sprintf("%d",$in);";
$out;
}
sub b2d{
my $in=shift;
my $out=o2d(b2o($in));
}
Montage of finished needlework projects for framing
|
|
Neoperl Faucet Aerator Water saving Bathroom/ Kitchen 1.0 gpm $2.99 WaterSense Listed. Neoperl 1.0 gpm, dual thread aerator( Dual threaded to fit both male and female ends). Best quality and performance at a lower cost. NSF 61 approved. Aerated stream produces a larger and whiter stream that is soft to the touch and non-splashing. Pressure compensating for a consistently even flow. 15/16″ standard male and 55/64″ standard female threads…. |
|
|
Web Applications: Concepts & Real World Design $78.96 This unique text explores the core concepts central to the development of three-tier, client-server Web applications. A comprehensive introduction to the Internet and Web applications is followed by a brief refresher on HTML and CSS and an introduction to client-side programming using JavaScript and browser objects. The heart of the book features a thorough exploration of concepts such as dynamica… |
|
|
Professional Perl Programming $39.97 Perl is one of the most important scripting languages in use today. Open source, freely available, portable, versatile, and robust, powerful and easy to use, Perl is the first choice for thousands of professional web developers. But Perl is far more than a scripting language for the web. Supported by a comprehensive standard library and hundreds of third-party libraries, Perl is an increasingly po… |
|
|
World War II Book Set 2 (Twenty and Ten, Behind the Bedroom Wall, Katarina, Torn Thread, Four Perfect Pebbles: A Holocaust Story) … |
