From 9291e4bf702dd086172f8e010dac00ab3f370c82 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Wed, 26 Oct 2022 13:15:50 -0700 Subject: add ping_log script --- scripts/network/ping_log | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 scripts/network/ping_log diff --git a/scripts/network/ping_log b/scripts/network/ping_log new file mode 100755 index 00000000..878127b2 --- /dev/null +++ b/scripts/network/ping_log @@ -0,0 +1,31 @@ +#!/usr/bin/perl -w + +use POSIX; +use IO::Handle; + +@targets = ("4.2.2.2", "8.8.8.8", "10.132.128.1"); + +open $_, "-|", "ping", $_ for @targets; +-d or mkdir for "$ENV{HOME}/tmp"; +open LOG, ">>", "$ENV{HOME}/tmp/ping_log.txt"; +LOG->autoflush; +while (1) { + $to_print = ""; + for (@targets) { + $rin = ""; + vec($rin, fileno $_, 1) = 1; + next unless select $rin, undef, undef, 1; + $line = readline $_; + if ($line =~ /bytes from/ and not $status{$_}) { + $status{$_}++; + $to_print .= "$_ up, "; + } elsif ($line =~ /Unreachable/ and $status{$_}) { + $status{$_}--; + $to_print .= "$_ down, "; + } + } + next unless length $to_print; + $to_print = strftime("%c", localtime) . " " . substr $to_print, 0, -2; + print "$to_print\n"; + print LOG "$to_print\n"; +} -- cgit v1.2.3