I finally got a video card back in my old machine that I first learned Perl on. Going through the machine I found all my old code stowed away in a truecrypt drive. So, I re-coded this bit i called Sweep-N-Scan to work well with IO::Socket. Nothing really special, but i've noticed that the snippit count for my beloved first language is very very low. So, here's to you, Perl :)
#!/usr/bin/perl
# Basic ping sweeper and port checker
# by l3r1k
use IO::Socket::INET;
use Net::Ping;
$pinghost=$ARGV[0];
if(!defined $pinghost){
print "Usage: $0 <NetBlock (e.g. 192.168.1.1-255)> -scan(optional) <ports (up to 5)>\n";
exit;
}
if (($ARGV[1]) && ($ARGV[1] eq '-scan')){
$pc=$ARGV[1];
}
if ($ARGV[2]){
for ($av=2;$av<=6;$av++){
if ($ARGV[$av]) { push(@ports, $ARGV[$av]); }
}
}
print "\n";
if ($pinghost =~ /(\d{1,3}\.\d{1,3}\.\d{1,3}\.)([^-]+)-(\d{1,3})/) {
$ipfrag = $1;
$block_begin = $2;
$block_end = $3;
}
$p=Net::Ping->new("icmp", 1, 64);
while ($block_begin <= $block_end) {
$fullip = "$ipfrag$block_begin";
ping($fullip);
$block_begin++;
}
@offline;
sub ping {
$ip0=$_[0];
if ($p->ping($_[0])) {
print "[+] -> $_[0]\n";
if ($pc){
print " [Checking For Open Ports On $_[0]]\n\n";
print "++++++++ $_[0] ++++++++\n";
online_scan($ip0);
}
}
else
{
push(@offline, $_[0]);
}
}
sub online_scan {
foreach (@ports) {
$sock = IO::Socket::INET->new(PeerAddr => $_[0],
PeerPort => $_,
Proto => 'tcp');
if ($sock){
close $sock;
print "++++ [+] ---> $_ Open\n";
$port++;
}
else {
print "++++ [-] ---> $_ Closed\n";
$port++;
}
}
print "++++++++++++++++++++++++++++++\n";
print "\n";
}
print "Would you like to see the Offline hosts? ";
chomp($vol = <STDIN>);
print "\n";
if ($vol =~ /y\S*/i) {
foreach (@offline){
print "$_ offline.\n";
}
}
print "\n";
print "[++++++++++++++++++]\n";
print "[+] Sweep-N-Scan [+]\n";
print "[+] By l3r1k [+]\n";
print "[++++++++++++++++++]\n";