Updated 2014-05-08 11:14:16 by LGT

A script to scan tcp port.

It runs successfully on Linux but it seems not ok on Mac os X.

It must be run as root (or with sudo) to report the correct list of ports used.

It loops infinitely, hence you have to use Ctrl-C to quit.
# scanport.tcl --
#
# script interrogeant les ports TCP en boucle
# et affichant la liste des ports utilisés précédée de l'horodatage
#
# A utiliser en tant qu'utilisateur root
# utiliser Ctrl-C pour quitter la boucle infinie
#
# Auteur: Laurent D. Gateau
#

# intervalles entre deux scans en nombre de secondes.
set interval 15

proc trace {} {
        set now [clock format [clock seconds] -format "%Y%m%dT%H:%M:%S"]
        puts -nonewline stderr "$now;"
        set k 65535
        while {$k > 0} {
                if [catch {
                        set s [socket -server accept $k]
                        close $s
                }] {
                        puts -nonewline stderr "$k,"
                }
                set k [expr $k - 1]
        }
        puts stderr ""
}

while {1} {
        trace
        exec sleep $interval
}