#!/usr/bin/perl
# nss - Written By Narrow (nss@privacyx.com)

# Needed Files
$|++;
use Socket; use Getopt::Std;
require 'include/banner.rs';
require 'include/logger.rs';
require 'include/report.rs';
require 'include/count.rs';
require 'include/mail.rs';
require 'include/modes.rs';
require 'nss.conf';

# Main Code [-START-]
getopts("h:l:m:", \%args);
&banner;
if(!defined $args{h}) {
print <<"EOT";
Usage: (perl) $0 <options> ...

Options:
-h [host file ]	-> File with hosts that will be scanned
-l [log  file ]	-> File where the results are saved (default: [hostfile].log)
-m [email addr]	-> Send the results to <email addr>

EOT
exit;
}
if(!defined $args{l}) { $logfile = "$args{h}.log"; } else { $logfile  = $args{l}; }
$hostfile = $args{h}; $mailto = $args{m};

# Plugins
print "Loading Plugins ...\n";
opendir(DIR, "plugin/unix");
while($in=readdir(DIR)) {
    next if ($in=~/^[.]{1,2}/);
    next if !($in=~/\.rs$/);
    require "plugin/unix/$in";
}
closedir(DIR);

opendir(DIR, "plugin/windows");
while($in=readdir(DIR)) {
    next if ($in=~/^[.]{1,2}/);
    next if !($in=~/\.rs$/);
    require "plugin/windows/$in";
}
closedir(DIR);

print "Loading $hostfile ... "; $count = 0;
count("$hostfile");
foreach $cnn (@cnt) { $count++; }
if($count <= 0) { print "File \"$hostfile\" Possible Empty!\n\n"; exit; }
print "$count Host(s) Found!\n\n"; $now=1;
foreach $host (@cnt) {
    chomp($host);
    &logs("$logfile","open");
    &report($host, $now, $count, "$hostfile.rpt");
    print "Scanning $host \($now of $count\)\n";
    if($scan_mode == 0) { &winscan($host); }
    elsif($scan_mode == 1) { &unxscan($host); }
    elsif($scan_mode == 2) { &detscan($host); }
    else { print "Unknow mode. Trying to detect ...\n"; &detscan($host); }
    $now++;
    &logs("$logfile","close");
}
if(length($mailto) != 0) { &mailer($mailto, $logfile); }

print "\nEND.\n";
exit(0);

# Main Code [-END-]