~mikini/hometools

ref: 637040b13e70a39c89ba1e76df7dfeed6a0fe916 hometools/port_monitor -rwxr-xr-x 383 bytes
637040b1 — Mikkel Kirkgaard Nielsen Add COPYING and README.md 6 months 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