- 论坛徽章:
- 0
|
本帖最后由 fangrm1988 于 2013-01-28 10:15 编辑
hi,all,帮看下这个多线程的端口扫描脚本哪里写的不对的,目前发现2个问题。脚本主要是对mssql数据库中的表下存放的大量域名进行端口扫描,将扫描出来的开放端口更新到数据表中,为了提高效率,所以需要加上多线程的操作,但不是很熟悉多线程,需要请各位帮忙看看那里的问题。
1、测试发现脚本执行后,会对表中的列domainname域名全部提取出来进行nmap扫描,不知道该如何限制呢,一次限制为几十个这样。
2、扫描中测试nmap有端口输出,但是无法更新的数据库中。- #!/usr/bin/perl
- use strict;
- use warnings;
- use DBI;
- use threads;
- my $dsn = 'DBI:Sybase:server=sql1';
- my $dbh = DBI->connect($dsn, "test", 'test.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;
复制代码 |
|