I tried implement script, but hosting does not support these modules:
Net::Scan::Ftp::Anonymous,
Net::Scan::Fork
as they require Perl 5.8.6. (they currently running Perl 5.8.5)

#!/usr/bin/perl use strict; use CGI; use CGI::Carp qw(fatalsToBrowser); use Net::IP; use Net::Scan::Ftp::Anonymous; use Net::Scan::Fork; use Time::HiRes qw(usleep ualarm gettimeofday tv_interval); $|=1; my $q = new CGI; print $q->header(); print_top($q); if ($q->param()){ display_results($q); } else { print_form($q); } print_end($q); exit(0); sub print_top{ print $q->start_html( -title => 'test', ); print "<h1>title</h1>"; } sub print_end { print "<hr>bla bla"; print $q->end_html; } sub print_form { my ($q) = @_; print $q->start_form( -name => 'main', -method => 'POST',); print 'Insert IP Address (<i>dotted decimal notation. Es. 192. +168.0.1 or 192.168.0.1-192.168.0.10 or 192.168.0.0/24</i>)'; print '<br><br>'; print $q->textfield(-name => "host", -size => 30); print '<br><br>'; print $q->submit(-value => 'Submit'); print $q->end_form; } sub display_results { my ($q) = @_; my @hosts; my $ip = $q->param('host'); my $newip = new Net::IP ("$ip"); do { push @hosts,$newip->ip(); } while (++$newip); my $thosts = $#hosts; $thosts++; print "$thosts hosts to scan. Let's go...<br><br>"; my $start_time = [gettimeofday]; Net::Scan::Fork::settings(20,4,3,60); foreach (@hosts){ Net::Scan::Fork::scan(\&scan,50,$_); } Net::Scan::Fork::wait_child; my $end_time = [gettimeofday]; my $elapsed = tv_interval($start_time,$end_time); print "<br>Completed in $elapsed seconds!<br>"; } sub scan { my $ip = shift; chomp $ip; $ip =~ s/^\s+|\s+$|\s+//g; if ($ip =~ /^([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|2 +5[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5]) +$/ or $ip =~ /^([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25 +[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])- +([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\ +d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])$/){ my $scan = Net::Scan::Ftp::Anonymous->new({ host => $ip, timeout => 3, verbose => 1, debug => 0 }); my $results = $scan->scan; print "$ip $results<br>" if $results; }else{ print '<br><b>Error:</b> no valid request.<br><br>'; } }

So i need instead of using perl modules and loading it into script, to embedd it code right into script. I do, but not this work. Any specific code correction will be appreciated.

#!/usr/bin/perl use strict; use CGI; use CGI::Carp qw(fatalsToBrowser); use Net::IP; use Net::Scan::Ftp::Anonymous; use Net::Scan::Fork; use Time::HiRes qw(usleep ualarm gettimeofday tv_interval); $|=1; my $q = new CGI; print $q->header(); print_top($q); if ($q->param()){ display_results($q); } else { print_form($q); } print_end($q); exit(0); sub print_top{ print $q->start_html( -title => 'test', ); print "<h1>title</h1>"; } sub print_end { print "<hr>bla bla"; print $q->end_html; } sub print_form { my ($q) = @_; print $q->start_form( -name => 'main', -method => 'POST',); print 'Insert IP Address (<i>dotted decimal notation. Es. 192. +168.0.1 or 192.168.0.1-192.168.0.10 or 192.168.0.0/24</i>)'; print '<br><br>'; print $q->textfield(-name => "host", -size => 30); print '<br><br>'; print $q->submit(-value => 'Submit'); print $q->end_form; } sub display_results { my ($q) = @_; my @hosts; my $ip = $q->param('host'); my $newip = new Net::IP ("$ip"); do { push @hosts,$newip->ip(); } while (++$newip); my $thosts = $#hosts; $thosts++; print "$thosts hosts to scan. Let's go...<br><br>"; my $start_time = [gettimeofday]; Net::Scan::Fork::settings(20,4,3,60); ----- $| = 1; my (@load,@pids); my ($load,$pid,$npids); my ($max_processes,$smax_processes,$nload,$sload,$sleep); sub settings{ ($smax_processes,$nload,$sload,$sleep) = @_; } sub scan{ my ($job,$max_processes,$host) = @_; my $oldmax_processes = $max_processes; @load = Sys::CpuLoad::load(); $load = $load[0]; if ($load > $nload){ $max_processes = $smax_processes; sleep $sleep; } else{ $max_processes = $oldmax_processes; } $pid = fork(); if ($pid>0){ $npids++; if ($npids >= $max_processes){ for (1..($max_processes)){ my $wait_ret=wait(); if ($wait_ret>0){ $npids--; } } } } elsif (undef $pid){ print " Fork error!\n"; exit(0); } else{ alarm 0; $job->($host); exit(0); } } sub wait_child{ for (1..$npids){ my $wt = wait(); } } 1; ----- foreach (@hosts){ Net::Scan::Fork::scan(\&scan,50,$_); } Net::Scan::Fork::wait_child; ------- $| = 1; my (@load,@pids); my ($load,$pid,$npids); my ($max_processes,$smax_processes,$nload,$sload,$sleep); sub settings{ ($smax_processes,$nload,$sload,$sleep) = @_; } sub scan{ my ($job,$max_processes,$host) = @_; my $oldmax_processes = $max_processes; @load = Sys::CpuLoad::load(); $load = $load[0]; if ($load > $nload){ $max_processes = $smax_processes; sleep $sleep; } else{ $max_processes = $oldmax_processes; } $pid = fork(); if ($pid>0){ $npids++; if ($npids >= $max_processes){ for (1..($max_processes)){ my $wait_ret=wait(); if ($wait_ret>0){ $npids--; } } } } elsif (undef $pid){ print " Fork error!\n"; exit(0); } else{ alarm 0; $job->($host); exit(0); } } sub wait_child{ for (1..$npids){ my $wt = wait(); } } 1; ------ my $end_time = [gettimeofday]; my $elapsed = tv_interval($start_time,$end_time); print "<br>Completed in $elapsed seconds!<br>"; } sub scan { my $ip = shift; chomp $ip; $ip =~ s/^\s+|\s+$|\s+//g; if ($ip =~ /^([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|2 +5[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5]) +$/ or $ip =~ /^([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25 +[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])- +([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\ +d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])$/){ ------ $| = 1; sub scan { my $self = shift; my $host = $self->host; my $port = $self->port || 21; my $timeout = $self->timeout || 8; my $directory = $self->directory || 'test007'; my $user = $self->user || 'anonymous'; my $password = $self->password || 'postmaster@127.0.0.1'; my $verbose = $self->verbose || 0; my $debug = $self->debug || 0; my $ftp = Net::FTP->new( $host, Timeout => $timeout); my $results; if ($ftp){ if ($ftp->login($user,$password)){ if ($ftp->mkdir($directory)){ if ($verbose eq 0){ $results = "w"; } elsif ($verbose eq 1){ $results = "write access"; } $ftp->rmdir($directory); } else { if ($verbose eq 0){ $results = "r"; } elsif ($verbose eq 1){ $results = "read access"; } } } $ftp->quit; } else { $results = "ftp connection refused" if $debug; } return $results; } 1; ----- my $scan = Net::Scan::Ftp::Anonymous->new({ host => $ip, timeout => 3, verbose => 1, debug => 0 }); my $results = $scan->scan; print "$ip $results<br>" if $results; }else{ print '<br><b>Error:</b> no valid request.<br><br>'; } }


In reply to EMBEDD PM INTO SCRIPT CODE. by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.