Nc.pl

From wiki.perl.lt
Jump to: navigation, search
#!/usr/bin/perl
use strict;
# checks range of ip's for ssh using nc f.e. 10.1.11.1-254
# cretes x.x.x.x.nc.log with live ip's
# bug #1: does not filter entered ip.
# (c)-left algirdas
my $chkip=shift;
chomp($chkip);
  if ($chkip) {
    open(F,">$chkip\.nc.log");
    for (my $nr=1; $nr<255; $nr++) {
      my $ip = $chkip;
      $ip =~ s/x/$nr/g;
      print "checking $ip .. ";
      my $rep = `echo '' | nc $ip 22 |grep -v mismatch`;
      chomp($rep);
      if ($rep) {
        print "alive: $rep\n";
        print F "$ip - $rep\n";
      }
      else { print "dead\n"; }
    }
    close(F);
  }
  else { print "usage: $0 10.1.11.x\n" }
Personal tools
Categories