From a73df10f84bfcb223cd99bf790760c0909a7dd37 Mon Sep 17 00:00:00 2001 From: WTMike24 Date: Mon, 15 Aug 2022 23:06:22 +0000 Subject: [PATCH] Added vping --- perl/vping | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 perl/vping diff --git a/perl/vping b/perl/vping new file mode 100644 index 0000000..77d38f5 --- /dev/null +++ b/perl/vping @@ -0,0 +1,43 @@ +#!/usr/bin/perl + +use Term::ANSIColor; + +if ($ARGV[0] !~ /[a-z0-9\.]+/) { + print "Need... Arg...\n"; + exit 1; +} + +$dns=$ARGV[0]; + +my $regex=""; + +if ($^O == "linux") { + #$regex='([0-9]+ bytes) from ([a-z\.-]+) \(([0-9\.]+)\).*seq=([0-9]+).*time=([0-9\. ms]+)' + #$regex='(?[0-9]+ bytes) from (?[a-z\.-]+) \((?[0-9\.]+)\).*seq=(?[0-9]+).*time=(?[0-9\. ms]+)'; + $regex=qr/(?[0-9]+ bytes) from (?[a-z\.-]+) \((?[0-9\.]+)\).*seq=(?[0-9]+).*time=(?[0-9\.]+) ms/; + $dedjex=qr/no answer yet for icmp_seq=(?[0-9]+)/ +} elsif ($^O == "MSWin32") { + print "win!\n"; +} + +open(my $PING, "ping -O $dns|") or die "Cannot execute $!"; + +while (my $line = <$PING>) { + if ($line =~ $regex) { + #print "$4 - $5 - $2 ($3)\n"; + #print "$+{rseq} - $+{rms} - $+{rhost} ($+{rip})\n"; + 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 =~ $dedjex) { + print color("bright_red"); + printf "% 3s - no reply %s\n", $+{rseq}, $dns; + print color("reset"); + } else { + print $line; + } +} + +close($PING); +