Monday, August 29, 2011

Show ports and the applications bound to them


#!/bin/bash

netstat -lntup \
| awk '/^(tcp|udp)/ {print substr($4, match($4, ":[^:]+$") + 1) "/" $1, substr($NF, 1, index($NF, "/") - 1)}' \
| while read PORT PID
do
        BIN=$(readlink /proc/$PID/exe)
        echo $PORT $PID $BIN
done

No comments: