Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

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

by vinoth.ree (Parson)
on Jan 24, 2013 at 12:58 UTC ( #1015165=note: print w/ replies, xml ) Need Help??


in reply to Re^2: 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

Ok,fine. Then include the threads module into your code as

use threads;

within the while loop,create new thread for each domain name.

while ($line = $sth->fetchrow_array()) { #Your code goes here my $new_thread = threads->new(\&scan_domain, $line);</b> } sub scan_domain { my $domain_name = shift; print "started thread for $domain_name\n"; my @list =`nmap $line`; foreach(@list){ if($_=~/open/g){ $_ =~ s/\/.*//g; if($myport) {$myport=$myport.','.$_;chomp $myport;} else{$myport=$_; chomp $myport} }

Even you can return the $myport from the subroutine and update the table outside the subroutine or even you can have that table updating script inside the subroutine, its your wish.

If you want these threads to run as daemon process do not return from the subroutine use infinite loop to process in a frequent time.

Update:

Included threads cpan link


Comment on Re^3: how to write thread which was multithreaded port scan scripts for nmap
Select or Download Code
Re^4: how to write thread which was multithreaded port scan scripts for nmap
by Anonymous Monk on Jan 25, 2013 at 09:28 UTC
    thanks

    In order to improve the progress of the scan,i dont have enough ability to finish ,so Are trying to learn perl.

    i hope you will help me finish it,Write a complete script.

    thank you very much.

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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2014-08-01 10:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (2 votes), past polls