加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Perl 端口扫描的脚本(SYN)

发布时间:2020-12-16 00:01:50 所属栏目:大数据 来源:网络整理
导读:可能脚本会有Bug,我只是用来工作上用一下,具体有没有BUG没测。 项目估计马上结束了。 这个入库的是MYSQL的。原理是先Ping,如果通的话,则加入队列, 通过队列再进行SYN探测。 # !/usr/bin/perl use threads; use DBI; use Thread:: Queue; use Thread:: S

可能脚本会有Bug,我只是用来工作上用一下,具体有没有BUG没测。

项目估计马上结束了。 这个入库的是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 "全部跑完n"; last; } else { next; } } $se_max->down; threads->create(&;nex,$q->dequeue()); $progress->update() } foreach(threads->list()){ $_->join(); } print "n"; 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(); }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读