~mikini/hometools

hometools/port_monitor -rwxr-xr-x 383 bytes
158a6504 — Mikkel Kirkgaard Nielsen Exit on network error & indicate date of rate used a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#! /bin/bash

# Monitor connectivity to a set of TCP/UDP ports on the network

HOST=${1:-localhost}
PORTS=${2:-"80:443:8080"}
NCPARAMS="-z -w1"

while true; do
  echo -ne "\e[G$(date -Is) - ";
  for p in ${PORTS//:/ }; do
    if nc $NCPARAMS $HOST $p; then
      echo -en "\e[32m";
    else
       echo -en "\e[41;37m";
    fi;
    echo -en "$HOST:$p\e[0m ";
  done;
  sleep 5;
done