Home | History | Annotate | Download | only in scripts
      1 #! /bin/sh
      2 ## duplicate DaveG's ident-scan thingie using netcat.  Oooh, he'll be pissed.
      3 ## args: target port [port port port ...]
      4 ## hose stdout *and* stderr together.
      5 ##
      6 ## advantages: runs slower than ident-scan, giving remote inetd less cause
      7 ## for alarm, and only hits the few known daemon ports you specify.
      8 ## disadvantages: requires numeric-only port args, the output sleazitude,
      9 ## and won't work for r-services when coming from high source ports.
     10 
     11 case "${2}" in
     12   "" ) echo needs HOST and at least one PORT ; exit 1 ;;
     13 esac
     14 
     15 # ping 'em once and see if they *are* running identd
     16 nc -z -w 9 "$1" 113 || { echo "oops, $1 isn't running identd" ; exit 0 ; }
     17 
     18 # generate a randomish base port
     19 RP=`expr $$ % 999 + 31337`
     20 
     21 TRG="$1"
     22 shift
     23 
     24 while test "$1" ; do
     25   nc -v -w 8 -p ${RP} "$TRG" ${1} < /dev/null > /dev/null &
     26   PROC=$!
     27   sleep 3
     28   echo "${1},${RP}" | nc -w 4 -r "$TRG" 113 2>&1
     29   sleep 2
     30 # does this look like a lamer script or what...
     31   kill -HUP $PROC
     32   RP=`expr ${RP} + 1`
     33   shift
     34 done
     35 
     36