#!/bin/sh
# blaf
# Class A Scanner
# Greetings to all pC-fREAK Memberz -=== www.pc-freak.org ===-
# Say NO ! To Micro$oft. ... join us now and share the software you'll be free.
# Under GPL License Ver. 2.0 and above.
# All Copyrights and copylefts me hipodilski (C) :P
# Here is the painkiller This is the painkiller !

# Declares where is the scanner.
scanner_path='/home/hipo/httpcheck.sh';
# Includes the scanner funcs and vars.
source $scanner_path;

# Declares first,second and third arguments entered on the cmd.
string1="$1";
string2="$2";
string3="$3";

# Uses Vars declared in $scanner_path file;
String1="$A1";
String2="$A2";
String3="$A3";
String4="$A5";
String5="$A6";

# Declares the start_ip needed later for the stats during interrupt
start_ip="$String1.$String2.$String3.$String4";
stats_file="$log_dir/stats";
start_time=`date`;

# Traps so if we interrupt the prog. we get stats file etc.
trap trapp INT;

# trapp function calls the stats () function
trapp () {
stats;
}

# Generates statistic stuff for the scan.
stats () { 
end_time=`date`;
touch $stats_file;
cat /dev/null > $stats_file;
echo "Scan Interrupted ...";
echo "Thanx For Using This Anti M$ Product | pC-fREAK Ownz Ur Ass!";
echo -e "Scanner Stats:" >> $stats_file;
echo "----------------\n" >> $stats_file;
echo -e "Scan Started on: $start_time" >> $stats_file;
echo -e "Scan Ended on: $end_time" >> $stats_file;
echo -e "Hosts Scanned: $Count" >> $stats_file;
echo -e "Start IP: $start_ip" >> $stats_file;
echo -e "End IP: $String1.$String2.$String3.$String4" >> $stats_file;
echo "Stats File Written to: $log_dir";
exit 0
}

# Function that makes some checks to make the scanner work for class A networks.
ip_checks () {
host_count='0';
help_val='1';

# Infinite loop before the first octet of the ip gets value=255.
while [ 1 ]; do

# Does Counts for $Count which contains how many hosts are scanned.
#  Needed for stats during exit.
host_count=$(( $host_count + $help_val ));
count=$(( ($String5 - $String4) + 1 ));
Count=$(( ($count * $host_count) + $count ));

# Octet Checking Stuff.
if [ "$String5" == "255" ]; then
String3=$(( $String3 + 1 ));

# Calls The Scanner function.
scanner;
fi
if [ "$String3" == "255" ]; then
echo "Class C Scanned Reversing to the next Class";
String3='0';
String2=$(( $String2 + 1 ));

# Calls The Scanner function.
scanner;
fi
if [ "$String2" == "255" ]; then
echo "Class B Scanned Reversing to he next Class";
String2='0';
String1=$(( $String1 + 1 ));

# Calls The Scanner function.
scanner;
fi

# Checks is the Class A Scanning Completed?
if [ "$String1" == "255" ]; then
echo 'Class A Scanned :-]]]';
echo -e "\nGreetings Major\n\n";
echo 'See logs and stats for details ...';
echo 'for more -=== www.pc-freak.org ===-';
stats;
exit 0
fi
done
}

# Does The Scanning job. Calls the scanner with args. 
scanner () {
#echo $scanner_path $String1.$String2.$String3.$String4-$String5 $string2 \
#$string3;
$scanner_path $String1.$String2.$String3.$String4-$String5 $string2 \
$string3;
}

# Main Function Calls All the func. stuff above.
main () {
ip_checks;
}
main;
