Added unreachable regex & ctrl+c capture

master
parent c3b614b2a9
commit a819e4b860

@ -12,11 +12,12 @@ if ($ARGV[0] !~ /[a-z0-9\.]+/) {
my $dns=$ARGV[0];
my $regex;
my $dedjex;
my $destjex;
my $pingcmd;
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/;
$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]+)/;
$pingcmd="ping -O";
} elsif ($^O == "MSWin32") {
@ -31,12 +32,18 @@ if ($^O == "linux") {
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>) {
if ($line =~ $regex) {
if ($+{rms} > 100) {print color("bright_red");}
elsif ($+{rms} > 50) {print color("bright_yellow");}
printf "% 3s - % 4s ms - %s (%s)\n", $+{rseq}, $+{rms}, $+{rhost}, $+{rip};
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) {
print color("bright_red");
printf "% 3s - no reply %s\n", $+{rseq}, $dns;
@ -47,4 +54,3 @@ while (my $line = <$PING>) {
}
close($PING);

Loading…
Cancel
Save