jeremy.fang has asked for the wisdom of the Perl Monks concerning the following question:
There is a port scanner scripts and include thread ,but dont finished,so please someone can help me finish it.
I have many domain names in psinfo table(about 1000w) and want to scan those domain names with nmap command,then update result of scanner to table.
now has 2 question:
1、thread dont have Limit the largest number of process running,how to limit?
2、my scirpt dont update date to mssql,the nmap scan process has finshed, but the row "port" is a blank,not null。
use perl debug command ,the namp command had scaned the domain names and port had display by the script's print command ,but did not update to database.
there is thread scripts
#!/usr/bin/perl use strict; use warnings; use DBI; use threads; my $dsn = 'DBI:Sybase:server=sql1'; my $dbh = DBI->connect($dsn, "test", 'oray.com'); die "unable to connect to server $DBI::errstr" unless $dbh; $dbh->do("use portscan"); my $query = "SELECT domainname FROM psinfo"; my $sth = $dbh->prepare ($query) or die "prepare failed\n"; $sth->execute() or die "unable to execute query $query error $DBI::e +rrstr"; my $line; my $myport; while ($line = $sth->fetchrow_array()) { my $new_thread = threads->new(\&scan_domain, $line); print "$myport\n"; #for test my $upd_sth = $dbh->prepare("update psinfo set port=\'$myport\' where +domainname=\'$line\'"); $upd_sth->execute() or die "unable to execute update line where name i +s $line! error $DBI::errstr"; $upd_sth->finish; } sub scan_domain { my $s_myport; my $domain_name = shift; print "started thread for $domain_name\n"; my @list =`nmap $line`; foreach(@list){ if($_=~/open/g){ $_ =~ s/\/.*//g; if($s_myport) {$s_myport=$s_myport.','.$_;chomp $s_myport;} else{$s_myport=$_; chomp $s_myport} } } $myport=$s_myport; } $sth->finish;
there is no thread scripts
#!/usr/bin/perl use strict; use warnings; use DBI; my $dsn = 'DBI:Sybase:server=sql1'; my $dbh = DBI->connect($dsn, "test", 'oray.com'); die "unable to connect to server $DBI::errstr" unless $dbh; $dbh->do("use portscan"); my $query = "SELECT domainname FROM psinfo"; my $sth = $dbh->prepare ($query) or die "prepare failed\n"; $sth->execute() or die "unable to execute query $query error $DBI::e +rrstr"; my $line; my @list; while ($line = $sth->fetchrow_array()) { my $myport; my @list =`nmap $line`; foreach(@list){ if($_=~/open/g){ $_ =~ s/\/.*//g; if($myport){$myport=$myport.','.$_;chomp $mypo +rt;} else{$myport=$_; chomp $myport} } } print "$myport\n"; #for test my $upd_sth = $dbh->prepare("update psinfo set port=\'$myport\' where +domainname=\'$line\'"); $upd_sth->execute() or die "unable to execute update line where name i +s $line! error $DBI::errstr"; $upd_sth->finish; } $sth->finish;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: the multiple thread port scanner scripts issue
by roboticus (Chancellor) on Jan 26, 2013 at 14:34 UTC | |
by jeremy.fang (Initiate) on Jan 28, 2013 at 07:13 UTC | |
Re: the multiple thread port scanner scripts issue
by NetWallah (Canon) on Jan 26, 2013 at 17:07 UTC |
Back to
Seekers of Perl Wisdom