#! /usr/bin/perl use strict; use warnings; use Parallel::ForkManager; my @arr; my $PORT_NO = '80'; # Default port of HTTP my $SERVICE = "http"; my $pm = new Parallel::ForkManager(20); # At any instant maximum 20 processes can run simultaneously my $ip; # Stores the IP address supplied by user if (!$ARGV[0]) { print "Program intended to check the machines where webserver is running. \n"; print "USAGE: perl wst.pl [ip(xxx.xxx.xxx)] \nInput only 3 octets \n"; exit; } if ($ARGV[0] =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}$/) { $ip = $ARGV[0]; } else { print "Enter IP in valid format (xxx.xxx.xxx) \n"; print "USAGE: perl wst.pl [ip(xxx.xxx.xxx)] \n"; exit; } foreach my $i (1..254) { my $ip_add = sprintf("%s.%s",$ip,$i); #print $ip_add; my $pid = $pm->start and next; my $val = `nmap -sT -p $PORT_NO $ip_add | grep $SERVICE`; #print $val; if ($val) { my $test = (split(/\s+/,$val))[1]; if ($test =~ m/open/) { #print "Web Server at $ip_add is running.\n"; push (@arr,$ip_add); #print "@arr\n"; } } $pm->finish; } print "reaping....might take some time\n"; $pm->wait_all_children; print "Web Server is running at : @arr \n"; exit 0;