cancel
Showing results for 
Search instead for 
Did you mean: 

TCP ports reports

Olivier LEGRAND
Frequent Advisor

TCP ports reports

Hi,

I just want to regularly check with a shell script my open TCP ports.

How can I do that?

Regards for your help.
6 REPLIES
harry d brown jr
Honored Contributor

Re: TCP ports reports

Get lsof:

http://hpux.cs.utah.edu/hppd/hpux/Sysadmin/lsof-4.61/


live free or die
harry
Live Free or Die
MARTINACHE
Respected Contributor

Re: TCP ports reports

netstat -an |grep LISTEN |sort -u
Patrice MARTINACHE
Tore_1
Regular Advisor

Re: TCP ports reports

perhaps something like :

in shell script :


netstat -an | grep tcp | mailx -s "open tcp ports" youmailaddress

schedule the shell script to run from crontab.

If you have lsof installed, you can substitute
netstat with lsof -i tcp .


Steve Steel
Honored Contributor

Re: TCP ports reports

Hi


lsof is a good tool


else

#!/bin/ksh
netstat -an |head -n 2
netstat -an |tail -n +3|grep tcp


Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
harry d brown jr
Honored Contributor

Re: TCP ports reports

Olivier,

code sniplet for KSH using lsof:

WHOAMI=$$
#
# "tr" is used to remove all extra spaces,
# TWO SPACES in first pair of quotes, ("bb" - where b = blank) then
# ONE SPACE in second pair of quotes ("b" - where b = blank)
#
WHATisSOCKET=`//usr/local/bin/lsof -U -a -p $WHOAMI|grep " 0t"|tr -s " " " "|cut -d"
" -f9`


echo $WHATisSOCKET

live free or die
harry
Live Free or Die
harry d brown jr
Honored Contributor

Re: TCP ports reports

Or

WHATisSOCKET=`/usr/local/bin/lsof -P -p $WHOAMI|grep -e " unix " -e " inet "|grep -e " TCP " -e " UDP "`


live free or die
harry
Live Free or Die