首页 > 代码库 > 简练的端口扫描脚本
简练的端口扫描脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | #!/usr/bin/env perl ( $sec , $min , $hour , $mday , $mon , $year ) = ( localtime )[0..5]; ( $sec , $min , $hour , $mday , $mon , $year ) = ( sprintf ( "%02d" , $sec ), sprintf ( "%02d" , $min ), sprintf ( "%02d" , $hour ), sprintf ( "%02d" , $mday ), sprintf ( "%02d" , $mon + 1), $year + 1900 ); $date = "$year-$mon-$mday $hour:$min:$sec" ; ########################################################## open (FH, "/opt/monitor/port.list" ) || die ; while ( defined ( $port_tn =<FH>)) { ( $host_ip , $mod_n , $port_t , $port_n )= split (/\t/, $port_tn ); chomp $host_ip ; chomp $mod_n ; chomp $port_t ; chomp $port_n ; ch_result(); } #################################################### sub ch_result { open LOG, ">>/opt/monitor/port_status.log" ; select LOG; if ( $port_t eq ‘tcp‘ ){ `/usr/bin/nc -z -w2 $host_ip $port_n `; $flag = `echo $?`; } else { `/usr/bin/nc -u -z -w2 $host_ip $port_n `; $flag = `echo $?`; } ########################### if ( $flag != 0){ print "$date $host_ip $mod_n $port_t $port_n is closed!\n" ; } close (LOG); } |
1 2 | 172.16.2.2 httpd tcp 80 172.16.2.2 tomcat tcp 8080 |
1 2 | 2014-11-25 20:30:01 172.16.2.2 httpd tcp 80 is closed! 2014-11-25 20:30:01 172.16.2.2 tomcat tcp 8080 is closed! |
1 | * /5 * * * * cd /opt/monitor ; . /monitor_port .pl > /dev/null 2>&1 |
简练的端口扫描脚本
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。