Thursday, January 27, 2005

Unix Script to report network listeners

Some folks at worked were having problems with thier server visibility so I suggessted something like:

#!/bin/bash
TMPFILE=`/bin/mktemp`
ADMINS="linux-support@yourdomain.com"
BOX=`/bin/hostname -s`
/usr/sbin/lsof -i -n -P | /bin/grep '(LISTEN|UDP)' > $TMPFILE
/bin/cat $TMPFILE | mail -s "Network listeners for box $BOX" $ADMINS
[ -f $TMPFILE ] && /bin/rm -f $TMPFILE

Concerned about information disclosure? That's cool just add
TMPMAIL=`bin/mktemp`
cat $TMPFILE | gpg -e -a -r "Some Label for PGP enabled email user" > $TMPMAIL
cat $TMPMAIL > $TMPFILE

After the lsof line

Then at the end add
[ -f $TMPMAIL ] && /bin/rm -f $TMPMAIL

This could be its own script like /etc/cron.daily/linux_port_reporter.sh

0 Comments:

Post a Comment

<< Home