|
|
@ -12,11 +12,12 @@ if ($ARGV[0] !~ /[a-z0-9\.]+/) {
|
|
|
|
my $dns=$ARGV[0];
|
|
|
|
my $dns=$ARGV[0];
|
|
|
|
my $regex;
|
|
|
|
my $regex;
|
|
|
|
my $dedjex;
|
|
|
|
my $dedjex;
|
|
|
|
|
|
|
|
my $destjex;
|
|
|
|
my $pingcmd;
|
|
|
|
my $pingcmd;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($^O == "linux") {
|
|
|
|
if ($^O == "linux") {
|
|
|
|
$regex=qr/(?<bytes>[0-9]+ bytes) from (?<rhost>[a-z\.-]+) \((?<rip>[0-9\.]+)\).*seq=(?<rseq>[0-9]+).*time=(?<rms>[0-9\.]+) ms/;
|
|
|
|
$regex=qr/(?<bytes>[0-9]+ bytes) from (?<rhost>[a-z\.-]+) \((?<rip>[0-9\.]+)\).*seq=(?<rseq>[0-9]+).*time=(?<rms>[0-9\.]+) ms/;
|
|
|
|
|
|
|
|
$destjex=qr/From (?<rhost>[a-zA-Z0-9\.]+) \(?(?<rip>[0-9\.]*)\)? ?icmp_seq=(?<rseq>[0-9]+).*/;
|
|
|
|
$dedjex=qr/no answer yet for icmp_seq=(?<rseq>[0-9]+)/;
|
|
|
|
$dedjex=qr/no answer yet for icmp_seq=(?<rseq>[0-9]+)/;
|
|
|
|
$pingcmd="ping -O";
|
|
|
|
$pingcmd="ping -O";
|
|
|
|
} elsif ($^O == "MSWin32") {
|
|
|
|
} elsif ($^O == "MSWin32") {
|
|
|
@ -31,15 +32,21 @@ if ($^O == "linux") {
|
|
|
|
|
|
|
|
|
|
|
|
open(my $PING, "$pingcmd $dns|") or die "Cannot execute $!";
|
|
|
|
open(my $PING, "$pingcmd $dns|") or die "Cannot execute $!";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$SIG{'INT'} = sub { close($PING);print color("reset");print("\rexiting\n");exit 0;};
|
|
|
|
|
|
|
|
|
|
|
|
while (my $line = <$PING>) {
|
|
|
|
while (my $line = <$PING>) {
|
|
|
|
if ($line =~ $regex) {
|
|
|
|
if ($line =~ $regex) {
|
|
|
|
if ($+{rms} > 100) {print color("bright_red");}
|
|
|
|
if ($+{rms} > 100) {print color("bright_red");}
|
|
|
|
elsif ($+{rms} > 50) {print color("bright_yellow");}
|
|
|
|
elsif ($+{rms} > 50) {print color("bright_yellow");}
|
|
|
|
printf "% 3s - % 4s ms - %s (%s)\n", $+{rseq}, $+{rms}, $+{rhost}, $+{rip};
|
|
|
|
printf "% 3s - % 4s ms - %s (%s)\n", $+{rseq}, $+{rms}, $+{rhost}, $+{rip};
|
|
|
|
if ($+{rms} > 50) {print color("reset");}
|
|
|
|
if ($+{rms} > 50) {print color("reset");}
|
|
|
|
|
|
|
|
} elsif ($line =~ $destjex) {
|
|
|
|
|
|
|
|
print color("bright_red");
|
|
|
|
|
|
|
|
printf "% 3s - no reply %s: %s says unreachable\n", $+{rseq}, $dns, $+{rhost};
|
|
|
|
|
|
|
|
print color("reset");
|
|
|
|
} elsif ($line =~ $dedjex) {
|
|
|
|
} elsif ($line =~ $dedjex) {
|
|
|
|
print color("bright_red");
|
|
|
|
print color("bright_red");
|
|
|
|
printf "% 3s - no reply %s\n", $+{rseq}, $dns;
|
|
|
|
printf "% 3s - no reply %s\n", $+{rseq}, $dns;
|
|
|
|
print color("reset");
|
|
|
|
print color("reset");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
print $line;
|
|
|
|
print $line;
|
|
|
@ -47,4 +54,3 @@ while (my $line = <$PING>) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
close($PING);
|
|
|
|
close($PING);
|
|
|
|
|
|
|
|
|
|
|
|