From a819e4b860ae6026b613e8aff4cbdbd03d11c170 Mon Sep 17 00:00:00 2001 From: WTMike24 Date: Tue, 16 Aug 2022 13:27:39 +0000 Subject: [PATCH] Added unreachable regex & ctrl+c capture --- perl/vping | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/perl/vping b/perl/vping index a5544d0..16ba2f3 100755 --- a/perl/vping +++ b/perl/vping @@ -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/(?[0-9]+ bytes) from (?[a-z\.-]+) \((?[0-9\.]+)\).*seq=(?[0-9]+).*time=(?[0-9\.]+) ms/; + $destjex=qr/From (?[a-zA-Z0-9\.]+) \(?(?[0-9\.]*)\)? ?icmp_seq=(?[0-9]+).*/; $dedjex=qr/no answer yet for icmp_seq=(?[0-9]+)/; $pingcmd="ping -O"; } elsif ($^O == "MSWin32") { @@ -31,15 +32,21 @@ 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; + printf "% 3s - no reply %s\n", $+{rseq}, $dns; print color("reset"); } else { print $line; @@ -47,4 +54,3 @@ while (my $line = <$PING>) { } close($PING); -