1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-25 23:21:54 +03:00

Tests - eventscripts - add an nmap stub

Signed-off-by: Martin Schwenke <martin@meltin.net>

(This used to be ctdb commit 6ff9545a0fd58f0728b769c7b36d3b6ab7366321)
This commit is contained in:
Martin Schwenke 2011-08-22 15:56:57 +10:00
parent 7b2e79ab7f
commit e88df4289f

View File

@ -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