2

I'd like to be monitoring ports in "realtime" and the processes that use them. Is there any tool that can handle that? I imagine somethinkg like top, but with a column that lists all ports the process is using... or a list of ports, protocol, and the process that has that port open or is listenting to.

This is for Linux based OS.

vee
  • 103
  • 2

5 Answers5

4

Was just going to ask which OS and noticed that you edited to add that. You're in luck then. Try this quick and dirty one-liner (as root) in a BASH shell:

while true ; do output=$(netstat -anptu) ; clear ; echo "$output" ; sleep 2 ; done

edit: More concise, ordered output:

while true ; do output=$( (netstat -anpt | awk '{ print $1" "$4" "$7" "$6 }' | tail -n +3 ; netstat -anpu | awk '{ print $1" "$4" "$6 }' | tail -n +3 ) | egrep '[0-9]\/' | sort | uniq) ; clear ; date ; echo "$output" ; sleep 2 ; done
Joshua Huber
  • 817
  • 6
  • 7
2

You did not specify an OS. But if it is Linux (which I guess is likely, since you mention top), then there exist a tool called iftop, which can display the current bandwidth usage by IP address. This is not exactly what you asked for, but depending on your needs, might be close enough.

kasperd
  • 30,455
  • 17
  • 76
  • 124
2

Why wouldn't anyone suggest the -c option for netstat.

Add -c to your existing netstat command & it would show you the output live.

deppfx
  • 429
  • 3
  • 13
1

After some time I found nethogs, it's right what I needed in the first place:

It needs the device name as the first parameter, and must be run as sudo: sudo nethogs wlp9s0

0

Look at -i and -p options of lsof tool:

watch lsof -a -itcp -p <PID>

void
  • 101
  • 2