diff options
| author | Martin Schwenke <martin@meltin.net> | 2011-08-22 15:56:57 +1000 |
|---|---|---|
| committer | Martin Schwenke <martin@meltin.net> | 2011-08-30 16:51:55 +1000 |
| commit | e88df4289f84f06c5e35d5cecc2ab003f9e1e095 (patch) | |
| tree | 7211a4f6709271a040623d13316da448d942f352 | |
| parent | 7b2e79ab7f5c44ba70e8ab0632bdba17226a530f (diff) | |
| download | samba-e88df4289f84f06c5e35d5cecc2ab003f9e1e095.tar.gz samba-e88df4289f84f06c5e35d5cecc2ab003f9e1e095.tar.xz samba-e88df4289f84f06c5e35d5cecc2ab003f9e1e095.zip | |
Tests - eventscripts - add an nmap stub
Signed-off-by: Martin Schwenke <martin@meltin.net>
(This used to be ctdb commit 6ff9545a0fd58f0728b769c7b36d3b6ab7366321)
| -rwxr-xr-x | ctdb/tests/eventscripts/stubs/nmap | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/ctdb/tests/eventscripts/stubs/nmap b/ctdb/tests/eventscripts/stubs/nmap new file mode 100755 index 0000000000..15eebe6901 --- /dev/null +++ b/ctdb/tests/eventscripts/stubs/nmap @@ -0,0 +1,68 @@ +#!/bin/bash + +prog="nmap" + +usage () +{ + cat >&2 <<EOF +Usage: $prog -n -oG - -PS 127.0.0.1 -p <port>[,<port> ...] + +A fake nmap stub that prints items depending on the variable +FAKE_TCP_LISTEN and the ports specified. + +Note that all options apart from -p are ignored. + +EOF + exit 1 +} + +ports="" + +parse_options () +{ + _temp=$(getopt -n "$prog" -a -o "np:" -l help -l PS: -l oG: -- "$@") + + [ $? != 0 ] && usage + + eval set -- "$_temp" + + while true ; do + case "$1" in + -n) shift ;; + --oG|--PS) shift 2 ;; + -p) ports="${ports}${ports:+ }${2//,/ }" ; shift 2 ;; + --) shift ; break ;; + -h|--help|*) usage ;; # * shouldn't happen, so this is reasonable. + esac + done + + [ $# -gt 0 ] && usage + + [ -n "$ports" ] || usage +} + +# For printing out... +args="$*" + +parse_options "$@" + +port_states="" + +for p in $ports ; do + pn=$(getent services "$p" | sed -e 's@[[:space:]].*@@') + for i in $FAKE_TCP_LISTEN ; do + lp="${i##*:}" + if [ "$p" = "$lp" ] ; then + port_states="${port_states}${port_states:+, }${p}/open/tcp//${pn}///" + continue 2 + fi + done + port_states="${port_states}${port_states:+, }${p}/closed/tcp//${pn}///" +done + +cat <<EOF +# Nmap 5.21 scan initiated $(date) as: nmap $args +Host: 127.0.0.1 () Status: Up +Host: 127.0.0.1 () Ports: $port_states +# Nmap done at $(date) -- 1 IP address (1 host up) scanned in 0.04 seconds +EOF |
