Ping Sweeper & Port Checker

By l3r1k on Jan 23, 2009

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";

Comments

Sign in to comment.
IrcMafia   -  Dec 10, 2010

sorry.. intergrate is the term i guess

 Respond  
IrcMafia   -  Dec 10, 2010

l3r1k, can u convert that on an IRC PERL BOT?

 Respond  
Hawkee   -  Jan 23, 2009

l3r1k, you gotta use BBCode to bold your comment, not HTML.

 Respond  
l3r1k   -  Jan 23, 2009

I cant wait for no comments to show up :P

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.