#!/usr/bin/perl
# If they tried to use anything but 3 arguments - show them the
# usage instructions
if ($#ARGV + 1 > 0 && $#ARGV + 1 != 3) {
print "Usage: $0 <start> <end> <port>\n\n";
exit(1);
}
# Check for something that looks like an IP address, or prompt for one
until (@ARGV[0] =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
print "Enter the starting IP [192.168.0.1]: ";
$start=<STDIN>;
chomp $start;
if(! $start) { $start="192.168.0.1"; }
@ARGV[0]=$start;
}
# Get a number for the IP to stop at
until (@ARGV[1] =~ /^\d{1,3}$/) {
print "Enter the ending IP [254]: ";
$end=<STDIN>;
chomp $end;
if(! $end) { $end=254; }
@ARGV[1]=$end;
}
# Get a port number to scan on
until (@ARGV[2] =~ /^\d+$/) {
print "Enter the Port number to scan [80]: ";
$port=<STDIN>;
chomp $port;
if(! $port) { $port=80; }
@ARGV[2]=$port;
}
print "Scanning Port #@ARGV[2], from @ARGV[0] to @ARGV[1]\n";
# We need to get the last octet of the start IP somehow...
@class=split(/\./,@ARGV[0]);
use Socket;
$a=@class[3];
while ($a < @ARGV[1]) {
socket(SH, PF_INET, SOCK_STREAM, getprotobyname('tcp')) || die $!;
$ip="@class[0].@class[1].@class[2].${a}";
my $dest = sockaddr_in (@ARGV[2], inet_aton("${ip}"));
print "$ip\n";
if(system("ping -c1 $ip >/dev/null")) {
print "Host not pingable\n\n";
} else {
# If we're scanning port 80 we can just use lynx
if(@ARGV[2] eq 80) {
system("lynx -dump -head http://$ip");
} else {
# Otherwise proceed with opening a socket and reading the output
if (connect (SH, $dest)) {
$buffer = <SH>;
shutdown (SH,0) || die $!;
print "$buffer\n";
} else {
print "$!\n\n";
}
}
}
# Move to the next IP
$a++;
}
Last modified: Wednesday, December 31 1969 @ 19:00 EST
© Ian Samuel, 2012 http://braindump.MrZesty.net |