# RecordIface Linux BASH script # Records network traffic on a network interface # # Usage: RecordIface [TIMEPER] [OUTFILE] [APPEND] [GREPTEXT] # # [TIMEPER] - Determines how often a capture occurs # [OUTFILE] - Specifies output filename where traaffic is stored # [APPEND] - Append to an existing file, or create a new file # [GREPTEXT] - grep the output of netstat, filtering what is stored # if [ -z $1 ]; then echo echo Usage: RecordIface [TIMEPER] [OUTFILE] [APPEND] [GREPTEXT] echo echo No time period specified, defaulting to 600sec echo TIMEPER=600; else TIMEPER=$1; fi if [ -z $2 ]; then echo No output file specified, defaulting to RecordIface.log echo OUTFILE=RecordIface.log else OUTFILE=$2 fi if [ -z $3 ]; then echo Append mode not specifiec, defaulting to APPEND=0 echo APPEND=0 else APPEND=$3 fi if [ -z $4 ]; then echo No regular expression specified, storing ALL output from netstat echo REGEXPR=. else REGEXPR=$4 fi echo TIMEPER=$TIMEPER echo OUTFILE=$OUTFILE echo APPEND=$APPEND echo GREPTEXT=$REGEXPR echo while true; do echo -n . if [ $APPEND -eq 0 ]; then date > $OUTFILE netstat -i | grep $REGEXPR > $OUTFILE else date >> $OUTFILE netstat -i | grep $REGEXPR >> $OUTFILE fi sleep $TIMEPER; done