Arping.pl

From wiki.perl.lt
Jump to: navigation, search
#!/usr/bin/perl
use strict;
# arp-pings 3 times range of ip's f.e. 10.1.11.1-254
# cretes x.x.x.x.arp.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\.arp\.log");
    for (my $nr=1; $nr<255; $nr++) {
      my $ip = $chkip;
      $ip =~ s/x/$nr/g;
      print "checking $ip .. ";
      my $res = `arping -c 3 $ip`;
      if ($res =~ /Received\ [123]\ response/) {
        $res =~ s/\n//g;
        $res =~ s/(.*)\[(.*)\](.*)/$2/;
        print "alive $res\n";
        print F "$ip\t$res\n";
      }
      else { print "dead\n"; }
    }
    close(F);
  }
  else { print "usage: $0 10.1.11.x\n" }
Personal tools
Categories