Nmap Development mailing list archives
RE: Nmap & Bash Auto-Completion (was: Am I Missing Something?)
From: Daniel Miller <bonsaiviking () gmail com>
Date: Tue, 24 Nov 2009 21:59:47 -0600
Here's a bash-completion script for nmap that covers all the options
in the 5.00 release. There are some preference things that could be
changed, such as which options to tab-complete by default. I'm sure
there's a better way to do the comma-separated list of script
categories and names, but this works. Hope this helps!
Dan
# nmap bash completion file
# by Daniel Miller
NMAP_DIR="/usr/local/share/nmap"
_nmap() {
COMPREPLY=()
local cur prev common_options all_options file_opts time_opts
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
common_options="-i[INPUT_TARGETS] -s[SCAN_TECHNIQUES] -b -r -R -f
-D -S -e -g -d -p[PORTS] -F --top-ports --version-light --version-all
--script -O -P[PING_TYPE] -n --traceroute -T[TIMING] -o[OUTPUT_TYPE]
-v --reason --open -6 -A --randomize-hosts --version --help"
all_options="-iR --exclude -sL -sP -sS -sT -sA -sW -sM -sU -sN -sF
-sX -sI -sY -sZ -sO -sV -b -p -F -r --top-ports --port-ratio
--version-intensity --version-light --version-all --version-trace -sC
--script --script-args --script-trace --script-updatedb -O
--osscan-limit --osscan-guess -PN -PS -PA -PU -PY -PE -PP -PM -PO -n
-R --dns-servers --system-dns --traceroute -T --min-hostgroup
--max-hostgroup --max-retries --min-rate --max-rate -f --mtu -D -S -e
-g --source-port --data-length --ip-options --ttl --spoof-mac --badsum
--adler32 -oN -oX -oS -oG -oA -v -d --reason --open --packet-trace
--iflist --log-errors --append-output --webxml --no-stylesheet -6 -A
--datadir --send-eth --send-ip --privileged --unprivileged -V -h
--scanflags --allports -sR --max-os-tries --defeat-rst-ratelimit
--randomize-hosts --release-memory --interactive --version --help"
file_opts="-iL --excludefile --resume --stylesheet --servicedb --versiondb"
time_opts="--min-parallelism --max-parallelism --min-rtt-timeout
--max-rtt-timeout --initial-rtt-timeout --host-timeout --scan-delay
--max-scan-delay --stats-every"
if [[ "$cur" == - ]]; then
# Don't overwhelm the casual user.
# Only show single-letter and common options
COMPREPLY=( $( compgen -W "$common_options" -- $cur ) )
elif [[ "$cur" == -P+(S|Y|A|U|O) ]]; then
# Cannot have space between these pings and port list
COMPREPLY=( $( compgen -P "$cur" -- $cur ) )
elif [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W "$all_options $file_opts $time_opts"
-- $cur ) )
else
local any_file_opts any_time_opts
any_file_opts=$(echo $file_opts | sed -e 's/\s\+/|/g')
any_time_opts=$(echo $time_opts | sed -e 's/\s\+/|/g')
case "$prev" in
+($any_file_opts))
_filedir
;;
+($any_time_opts))
COMPREPLY=( $( compgen -W "${cur}s ${cur}m ${cur}h
$cur" -- $cur ) )
;;
-T)
COMPREPLY=( $( compgen -W "paranoid sneaky polite
normal aggressive insane" -- $cur ) )
;;
--version-intensity)
COMPREPLY=( $( compgen -W "0 1 2 3 4 5 6 7 8 9" -- $cur ) )
;;
--script)
categories=`perl -ne '$s{$1}=undef if/categories = {
"([^"]+)", /gc;$s{$1}=undef while(/\G"([^"]+)", /gc);END{$,=" ";print
keys %s}' $NMAP_DIR/scripts/script.db`
if [[ "$cur" == *,* ]]; then
local realcur prefix
realcur=${cur##*,}
prefix=${cur%,*}
COMPREPLY=( $( cd $NMAP_DIR/scripts/ >/dev/null &&
compgen -W "$categories all" -G "*.nse" -X
"!$realcur*" -P "$prefix," -- $realcur ) )
else
COMPREPLY=( $( cd $NMAP_DIR/scripts/ >/dev/null &&
compgen -W "$categories all" -G "*.nse" -X
"!$cur*" -- $cur ) )
fi
;;
-e)
_available_interfaces
;;
--spoof-mac)
COMPREPLY=( $( grep -i "^[^#]..... $cur"
$NMAP_DIR/nmap-mac-prefixes | cut -d\ -f2 ) )
;;
--datadir)
_filedir -d
;;
*)
return 0
;;
esac
fi
return 0
}
complete -F _nmap -o default nmap
#__END__
_______________________________________________
Sent through the nmap-dev mailing list
http://cgi.insecure.org/mailman/listinfo/nmap-dev
Archived at http://seclists.org/nmap-dev/
Current thread:
- Nmap & Bash Auto-Completion (was: Am I Missing Something?) Patrick Donnelly (Nov 23)
- Re: Nmap & Bash Auto-Completion (was: Am I Missing Something?) David Fifield (Nov 23)
- Re: Nmap & Bash Auto-Completion (was: Am I Missing Something?) Jay Fink (Nov 24)
- <Possible follow-ups>
- RE: Nmap & Bash Auto-Completion (was: Am I Missing Something?) Daniel Miller (Nov 25)
- Re: Nmap & Bash Auto-Completion (was: Am I Missing Something?) David Fifield (Dec 22)
- Re: Nmap & Bash Auto-Completion (was: Am I Missing Something?) Jay Fink (Dec 22)
- Re: Nmap & Bash Auto-Completion (was: Am I Missing Something?) David Fifield (Dec 22)
- Re: Nmap & Bash Auto-Completion (was: Am I Missing Something?) Jay Fink (Dec 22)
- Re: Nmap & Bash Auto-Completion Daniel Miller (Dec 23)
- Re: Nmap & Bash Auto-Completion (was: Am I Missing Something?) Jay Fink (Dec 24)
- Re: Nmap & Bash Auto-Completion (was: Am I Missing Something?) David Fifield (Dec 22)
- Re: Nmap & Bash Auto-Completion (was: Am I Missing Something?) David Fifield (Nov 23)
