Category: networking
Author/Contact Info LordScinawa
Description: you can use this to run nmap every x minutez :) :* btw.. my first useful program
#/usr/bin/perl
use warnings; 
use strict;
use File::Copy;


#enter here the path of your nmap!
    my $pathofnmap = "C:/Programmi/nmap-4.03";
#don't change :)
    my $mi = (localtime)[1];
#set in minute the gap between every scan
    my $gap=1;
#don't change :)
    my $mid; increm();


##################################################
print "Your personal namp executor\n";
print "\n";
print "                 LordScinawa    ;)\n";
##################################################

sub increm 
    { $mid = ($mi + $gap) % 60; }

sub meinz{
while(1)
{
    sleep 1;
    $mi = (localtime)[1];
    if ($mi >= $mid) {    
                    print"$mi, $mid\n";
                    increm();
                    esegui();  }
}

}
    
sub esegui {    
    chdir "$pathofnmap";
    if (open(NMAP, "nmap.exe -sS -P0 -S 127.0.0.1 -f -vv -O 80.104.113
+.95 |")){
    chdir "C:/Documents and Settings/Wxp/Documenti/pubz";
    
    if (open CAC, "+>", "cache.html") {
    print"opened cache\n";
        while (<NMAP>) {
            print"nmap!!\n";
            if (/\n/) {print (CAC "$_<br>\n");} 
            else {die "omfg";} }
    close CAC; 
    my $filetobecopied = "cache.html.";
    my $newfile = "nmapresult.html.";
    copy($filetobecopied, $newfile) or die "File cannot be copied.";
    print"copiati\n"; } else { die "Impossibile aprire/creare il file 
+di cache $! \n"};
    close NMAP;} else {die "Impossibile aprire Nmap $!\n"}}

meinz();
Replies are listed 'Best First'.
Re: ypne
by jwkrahn (Abbot) on Jul 04, 2006 at 11:29 UTC
    23 sub increm 24 { $mid = ($mi + $gap) % 60; }
    You shouldn't define subroutines that only have side effects. In other words, increm() returns a value and you should use that returned value to assign to the variable $mid.
    44 if (open CAC, "+>", "cache.html") {
    You are only writing to the CAC filehandle so there is no point in opening the file for reading as well.
    51 my $filetobecopied = "cache.html."; 52 my $newfile = "nmapresult.html."; 53 copy($filetobecopied, $newfile) or die "File cannot be cop +ied.";
    The file you opened is "cache.html" but the file you are trying to copy is "cache.html.", notice the difference in the file names.
    40 chdir "$pathofnmap"; 42 chdir "C:/Documents and Settings/Wxp/Documenti/pubz";
    Like open() and copy() in your program, you should verify that chdir() worked correctly.
    55 close NMAP;} else {die "Impossibile aprire Nmap $!\n"}}
    When using close with a piped open you should verify that the filehandle closed correctly.

    You may also want to peruse the style guide for tips on formatting your code. :)