Nmap Development mailing list archives

Re: Nmap & Bash Auto-Completion (was: Am I Missing Something?)


From: Jay Fink <jay.fink () gmail com>
Date: Tue, 24 Nov 2009 08:19:02 -0500

On Tue, Nov 24, 2009 at 12:24 AM, David Fifield <david () bamsoftware com> wrote:
On Mon, Nov 23, 2009 at 07:10:32PM -0500, Patrick Donnelly wrote:
On Mon, Nov 23, 2009 at 6:53 PM, Ron <ron () skullsecurity net> wrote:
A couple ideas, though:
- Have bash autocomplete for script names (not sure how that works, but

This is a great idea I think. How hard would it be to do this for all
of Nmap's options in addition to script names?

The documentation for Bash completion is here:

http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html
http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html

Using chgrp from Debian's /etc/bash_completion as an example, I made a
completion example that knows some option names and how to look up
scripts.

_nmap()
{
       local cur prev

       COMPREPLY=()
       cur=$(COMP_WORDS[COMP_CWORD])
       prev=${COMP_WORDS[COMP_CWORD-1])

       if [[ "$cur" == -* ]]; then
               COMPREPLY=( $(compgen -W '--script --script-args \
               --script-updatedb --traceroute \
               -sS -sP -sA -sM -sW -sV -O' -- $cur) )
               return 0
       fi

       if [ "$prev" == "--script" ]; then
               COMPREPLY=( $(cd /usr/share/nmap/scripts && compgen -f -- $cur) )
               return 0
       fi

       return 0
}
complete -F _nmap nmap

Save the above to a file and then source it like this:
       . ./nmap_comp

For example,
$ nmap -<tab><tab>
-O                 --script-args      -sP                -sW
-sA                --script-updatedb  -sS                --traceroute
--script           -sM                -sV
$ nmap --<tab><tab>
--script           --script-args      --script-updatedb  --traceroute
$ nmap --script ssh<tab><tab>
ssh-hostkey.nse  sshv1.nse

It would be neat if someone takes this idea further.

That is pretty slick. I definitely am trying this tonite :)
_______________________________________________
Sent through the nmap-dev mailing list
http://cgi.insecure.org/mailman/listinfo/nmap-dev
Archived at http://seclists.org/nmap-dev/


Current thread: