Using sed and awk to return a list of TCP and UDP ports that are 'listening' for connection requests.

Category: Software and Systems Engineering
Author: Sean O'Donnell
Thu, Jun. 12th, 2008 @ 1:43:56 (MDT)

The following command will return a list of 'listening' TCP and UDP Ports on a Linux-based OS.

netstat -puntl | grep -i "udp\|tcp" | awk {'print $4"\t"$1 '} | sed s/.*://

The command above will output a 2-column tab-delimited list, containing the port number, and protocol (TCP/6, UDP/6).

This output should help you determine which Network Services are running on a system, and to assess which services may need to be disabled, or blocked at the firewall-level.

This command helps me frequently generate reports from other scripts I've written for such administrative reporting and system monitoring processes.

Copyleft (<) 1998-2019