Concise Port Scan script and concise Port Scan script

Source: Internet
Author: User

Concise Port Scan script and concise Port Scan script

Script Name: monitor_port.pl

Purpose: scan for a specific port.

Script:

123456789101112131415161718192021222324252627282930313233343536373839404142434445 #!/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);}

File 1. port. list defines the port content to be scanned,

Eg:

12 172.16.2.2      httpd     tcp     80172.16.2.2      tomcat     tcp     8080

File 2. port_status.log records port Failure Information

Eg:

12 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!

Usage:

Just add this script to crontab!

1 */5 * * * * cd /opt/monitor; ./monitor_port.pl > /dev/null 2>&1

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.