Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^4: how to write thread which was multithreaded port scan scripts for nmap

by Anonymous Monk
on Jan 25, 2013 at 10:53 UTC ( #1015323=note: print w/ replies, xml ) Need Help??


in reply to Re^3: how to write thread which was multithreaded port scan scripts for nmap
in thread how to write thread which was multithreaded port scan scripts for nmap

now has 2 question
1、thread dont have Limit the number of running,how to limit?
2、my scirpt dont to update date to mssql
the nmap scan process has finshed, but the row "port" is a blank,not null。

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


Comment on Re^4: how to write thread which was multithreaded port scan scripts for nmap
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1015323]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2015-07-30 00:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (269 votes), past polls