Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 3 down vote accepted

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
share|improve this answer
    
This is great! I prefer this approach as I can customize it to whatever needs I have, thank you! – Luis Lobo Borobia May 30 '14 at 0:05
    
You can use the "watch" command in place of the wile loop. – dmourati Sep 27 '15 at 21:05

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.

share|improve this answer
    
Thanks, yes, it's for Linux, I've just edited the question to make it clear. I've seen that you can enable source and destination ports pressing capital S, and D. Thanks! – Luis Lobo Borobia May 29 '14 at 22:47
    
Is there a way to show the process too? – Luis Lobo Borobia May 29 '14 at 22:52
1  
@LuisLoboBorobia You could try watch 'netstat -ntlp' or variants of that. – kasperd May 29 '14 at 23:07
    
Thanks, that one is useful too. I prefer Joshua's answer though, as I can customize it. Thanks anyway! your answers were great too. – Luis Lobo Borobia May 30 '14 at 0:06

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

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.