Perl 포트 검색 스크립트(SYN)

5677 단어
아마도 스크립트에 버그가 있을 거예요. 저는 그냥 작업용으로 썼을 뿐이에요. 구체적으로 버그가 있는지 없는지 모르겠어요.
프로젝트는 곧 끝날 것 같다.이거 MYSQL 입고된 거예요.먼저 Ping을 수행하고 연결이 되면 큐에 추가합니다.
SYN 탐색은 대기열을 통해 다시 수행됩니다.
#!/usr/bin/perl
use threads;
use DBI;
use Thread::Queue;
use Thread::Semaphore;
use Net::Ping;
use Term::ProgressBar;



# create queue
my $q=new Thread::Queue;
# read for check list
my @target=<>;
my $se_max = Thread::Semaphore->new( 100 );
my $se_ping= Thread::Semaphore->new( 1000 );

foreach (@target){
  chomp($_);
  if(${$se_ping} <=0){
     for my $t(threads->list(threads::joinable)){
            $t->join();
            $se_ping->up();
      }
     redo;
  }
  $se_ping->down();
  threads->create(\&alive,$_);
}
for my $t(threads->list()){
   $t->join();
}

sub alive{
  my $ip =shift;
  $ping=Net::Ping->new();
  if($ping->ping($ip)){
      foreach my $port(1..65535){
         $q->enqueue("$ip|$port");
      }
  }
}

$all_sum=$q->pending();
print $all_sum;
my $progress = Term::ProgressBar->new({name  => '    ',count => $all_sum});
$progress->max_update_rate(1);

while(1){
  foreach(threads->list(threads::joinable))
  {
        $_->join();
  }

  my $item = $q->pending();

  if( $item == 0 )
  {
        my $active = threads->list(threads::running);
      if($active == 0)
        {
           print "    
"; last; } else { next; } } $se_max->down; threads->create(\&nex,$q->dequeue()); $progress->update() } foreach(threads->list()){ $_->join(); } print "
"; sub nex{ local($tmp)=shift; @list=split(/\|/,$tmp); my $scan = Net::Ping->new("syn"); $scan->port_number($list[1]); $scan->ping($list[0]); if($scan->ack){ db_insert($list[0],$list[1]); } $scan->close(); $se_max->up; } sub db_insert{ my $host=shift; my $port=shift; my $in=DBI->connect("DBI:mysql:database=port_scan;host=localhost","root","") or die "NO :$!"; my $insert=$in->do("insert into result(ip,port)values('$host',$port)"); $in->disconnect(); }

좋은 웹페이지 즐겨찾기