| 1 | #! /bin/shscip-shell filesystem . . `/bin/sh`. |
| 2 | ## Duplicate DaveG's ident-scan thingie using netcat. Oooh, he'll be p*ssed. |
| 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 | # Script author: Hobbit <[email protected]> |
| 11 | # Used in ABS Guide with permission. |
| 12 | |
| 13 | # --------------------------------------------------- |
| 14 | E_BADARGS=65 # Need at least two args. |
| 15 | TWO_WINKS=2 # How long to sleep. |
| 16 | THREE_WINKS=3 |
| 17 | IDPORT=113 # Authentication "tap ident" port. |
| 18 | RAND1=999 |
| 19 | RAND2=31337 |
| 20 | TIMEOUT0=9 |
| 21 | TIMEOUT1=8 |
| 22 | TIMEOUT2=4 |
| 23 | # --------------------------------------------------- |
| 24 | |
| 25 | case "${2}" in |
| 26 | "" ) echoscip-shell system . . echo. "Need HOST and at least one PORT." ; exit $E_BADARGS ;; |
| 27 | esac |
| 28 | |
| 29 | # Ping 'em once and see if they *are* running identd. |
| 30 | nc -z -w $TIMEOUT0 "$1" $IDPORT || \ |
| 31 | { echoscip-shell system . . echo. "Oops, $1 isn't running identd." ; exit 0 ; } |
| 32 | # -z scans for listening daemons. |
| 33 | # -w $TIMEOUT = How long to try to connect. |
| 34 | |
| 35 | # Generate a randomish base port. |
| 36 | RP=`exprscip-shell system . . expr. $$ % $RAND1 + $RAND2` |
| 37 | |
| 38 | TRG="$1" |
| 39 | shift |
| 40 | |
| 41 | while testscip-shell system . . test. "$1" ; do |
| 42 | nc -v -w $TIMEOUT1 -p ${RP} "$TRG" ${1} < /dev/nullscip-shell filesystem . . `/dev/null`. > /dev/nullscip-shell filesystem . . `/dev/null`. & |
| 43 | PROC=$! |
| 44 | sleepscip-shell system . . sleep. $THREE_WINKS |
| 45 | echoscip-shell system . . echo. "${1},${RP}" | nc -w $TIMEOUT2 -r "$TRG" $IDPORT 2>&1 |
| 46 | sleepscip-shell system . . sleep. $TWO_WINKS |
| 47 | |
| 48 | # Does this look like a lamer script or what . . . ? |
| 49 | # ABS Guide author comments: "Ain't really all that bad . . . |
| 50 | #+ kinda clever, actually." |
| 51 | |
| 52 | killscip-shell system . . kill. -HUP $PROC |
| 53 | RP=`exprscip-shell system . . expr. ${RP} + 1` |
| 54 | shift |
| 55 | done |
| 56 | |
| 57 | exit $? |
| 58 | |
| 59 | # Notes: |
| 60 | # ----- |
| 61 | |
| 62 | # Try commenting out line 30 and running this script |
| 63 | #+ with "localhost.localdomain 25" as arguments. |
| 64 | |
| 65 | # For more of Hobbit's 'nc' example scripts, |
| 66 | #+ look in the documentation: |
| 67 | #+ the /usr/share/doc/nc-X.XX/scripts directory. |