1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
#!/bin/bash
prog="nmap"
# Pretty that we're the shell and that this command could not be
# found.
if [ "$FAKE_NMAP_NOT_FOUND" = "yes" ] ; then
echo "sh: ${prog}: command not found" >&2
exit 127
fi
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
|