LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   count number of used ports (https://www.linuxquestions.org/questions/linux-general-1/count-number-of-used-ports-703501/)

mnchur 02-09-2009 10:22 PM

count number of used ports
 
I have been trying to create a superkaramba theme that shows my ports open/used at any given time. My problem comes in when I turn on transmission(bit torrent).

Bit torrent as you know uses just about every port on your comp and is making my script run its results over the size that I want so I looking for a way to lump all the ports for transmission together.

Idealy I would like to put a line in the app that has a total ports open count for transmission. here is what I have so far.

Code:

"netstat -pa --numeric-hosts |grep ':' | grep -v unix|grep -v '*'|grep -v '  - ' | sed 's/.*://' | sed 's/ .*  [0-9]/  /' | sed 's/ .*\// /' | sed 's/konqueror.*/konqueror/' | sed 's/kmail.*/kmail/' | sort -u | column -t;echo --------------------------------;nmap -F -e eth0 localhost |grep open"
I tried just greping out transmission and that works for getting rid of the problem but I would like to have some idea of just how many ports are being used by transmission. Any ideas

camh 02-10-2009 01:49 PM

"netstat -pa | grep -v unix | grep transmission | wc -l" should more or less work

Tinkster 02-10-2009 02:11 PM

Code:

netstat -pa | awk '$1 ~ /(tcp|udp)/ {print gensub(/.*:([^:]*$)/, "\\1", 1, $4)}'|sort -u|wc -l


All times are GMT -5. The time now is 12:49 AM.