add completion for netcat

- implement the most common netcat variants on Linux
  - nc.openbsd
  - nc.traditional
  - nc/netcat tries to guess which netcat is currently used
This commit is contained in:
Benjamin Kellermann 2020-04-10 16:57:50 +02:00 committed by Johannes Altmanninger
parent 0a40a6d551
commit de9f4cb252
6 changed files with 109 additions and 50 deletions

View File

@ -34,6 +34,7 @@
- `tig`
- `zopfli`, and `zopflipng`
- `nmap`, `ncat`
- `nc`, `netcat`, `nc.openbsd`, `nc.traditional`
### Deprecations and removed features

View File

@ -1,51 +1,12 @@
complete -c nc -d "Remote hostname" -x -a "(__fish_print_hostnames)"
# There a several different implementations of netcat.
# Try to figure out which is the current used one
# and load the right set of completions.
complete -c nc -s 4 -d "Use IPv4 only"
complete -c nc -s 6 -d "Use IPv6 only"
complete -c nc -s U -l unixsock -d "Use Unix domain sockets only"
complete -c nc -l vsock -d "Use vsock sockets only"
complete -c nc -s C -l crlf -d "Use CRLF for EOL sequence"
complete -c nc -s c -l sh-exec -x -d "Executes the given command via /bin/sh"
complete -c nc -s e -l exec -F -d "Executes the given command"
complete -c nc -l lua-exec -F -d "Executes the given Lua script"
complete -c nc -s g -x -d "Loose source routing hop points"
complete -c nc -s G -x -d "Loose source routing hop pointer"
complete -c nc -s m -l max-conns -x -d "Maximum simultaneous connections"
complete -c nc -s h -d "Show help"
complete -c nc -s d -l delay -x -d "Wait between read/writes"
complete -c nc -s o -l output -F -d "Dump session data to a file"
complete -c nc -s x -l hex-dump -F -d "Dump session data as hex to a file"
complete -c nc -s i -l idle-timeout -x -d "Idle read/write timeout"
complete -c nc -s p -l source-port -x -d "Specify source port to use"
complete -c nc -s s -l source -x -d "Specify source address"
complete -c nc -s l -l listen -d "Bind and listen for incoming connections"
complete -c nc -s k -l keep-open -d "Accept multiple connections in listen mode"
complete -c nc -s n -l nodns -d "Do not resolve hostnames via DNS"
complete -c nc -s t -l telnet -d "Answer Telnet negotiation"
complete -c nc -s u -l udp -d "Use UDP instead of default TCP"
complete -c nc -l sctp -d "Use SCTP instead of default TCP"
complete -c nc -s v -l verbose -d "Set verbosity level"
complete -c nc -s w -l wait -x -d "Connect timeout"
complete -c nc -s z -d "Zero-I/O mode, report connection status only"
complete -c nc -l append-output -d "Append rather than clobber specified output files"
complete -c nc -l send-only -d "Only send data, ignoring received"
complete -c nc -l recv-only -d "Only receive data, never send anything"
complete -c nc -l no-shutdown -d "Continue half-duplex when receiving EOF"
complete -c nc -l allow -x -d "Allow only given hosts to connect"
complete -c nc -l allowfile -F -d "A file of hosts allowed to connect"
complete -c nc -l deny -x -d "Deny given hosts from connecting"
complete -c nc -l denyfile -F -d "A file of hosts denied from connecting"
complete -c nc -l broker -d "Enable connection brokering mode"
complete -c nc -l chat -d "Start a simple chat server"
complete -c nc -l proxy -x -d "Specify address of host to proxy through"
complete -c nc -l proxy-type -x -a "http socks4 socks5" -d "Specify proxy type"
complete -c nc -l proxy-auth -x -d "Authenticate with HTTP or SOCKS proxy"
complete -c nc -l proxy-dns -x -a "local remote both none" -d "Specify where to resolve proxy destination"
complete -c nc -l ssl -d "Connect or listen with SSL"
complete -c nc -l ssl-cert -F -d "Specify SSL certificate file"
complete -c nc -l ssl-key -F -d "Specify SSL private key"
complete -c nc -l ssl-verify -d "Verify trust and domain name of certificates"
complete -c nc -l ssl-trustfile -F -d "PEM file containing trusted SSL certificates"
complete -c nc -l ssl-ciphers -x -d "Cipherlist containing SSL ciphers to use"
complete -c nc -l ssl-alpn -x -d "ALPN protocol list to use"
complete -c nc -l version -d "Display version information"
set -l flavor
if string match -rq -- '^OpenBSD netcat' (nc -h 2>&1)[1]
set flavor nc.openbsd
else
set flavor (basename (realpath (command -v nc)))
end
__fish_complete_netcat nc $flavor

View File

@ -0,0 +1 @@
__fish_complete_netcat nc.openbsd

View File

@ -0,0 +1 @@
__fish_complete_netcat nc.traditional

View File

@ -0,0 +1,12 @@
# There a several different implementations of netcat.
# Try to figure out which is the current used one
# and load the right set of completions.
set -l flavor
if string match -rq -- '^OpenBSD netcat' (netcat -h 2>&1)[1]
set flavor nc.openbsd
else
set flavor (basename (realpath (command -v netcat)))
end
__fish_complete_netcat netcat $flavor

View File

@ -0,0 +1,83 @@
function __fish_complete_netcat
set -l nc $argv[1]
set -l flavor $argv[-1]
switch $flavor
case busybox
complete -c $nc -s l -d "Listen mode, for inbound connects"
complete -c $nc -s p -x -d "Local port"
complete -c $nc -s w -x -d "Connect timeout"
complete -c $nc -s i -x -d "Delay interval for lines sent"
complete -c $nc -s f -r -d "Use file (ala /dev/ttyS0) instead of network"
complete -c $nc -s e -r -d "Run PROG after connect"
case ncat
complete -c $nc -w ncat
case nc.openbsd
complete -c $nc -s 4 -d "Forces nc to use IPv4 addresses only"
complete -c $nc -s 6 -d "Forces nc to use IPv6 addresses only"
complete -c $nc -s b -d "Allow broadcast"
complete -c $nc -s C -d "Send CRLF as line-ending"
complete -c $nc -s D -d "Enable debugging on the socket"
complete -c $nc -s d -d "Do not attempt to read from stdin"
complete -c $nc -s F -d "Pass the first connected socket using sendmsg(2) to stdout and exit"
complete -c $nc -s h -d "Prints out nc help"
complete -c $nc -s I -x -d "Specifies the size of the TCP receive buffer"
complete -c $nc -s i -x -d "Specifies a delay time interval between lines of text sent and received"
complete -c $nc -s k -d "Forces nc to stay listening for another connection after its current connection is completed"
complete -c $nc -s l -d "Used to specify that nc should listen for an incoming connection rather than initiate a connection to a remote host"
complete -c $nc -s M -x -d "Set the TTL / hop limit of outgoing packets"
complete -c $nc -s m -x -d "Ask the kernel to drop incoming packets whose TTL / hop limit is under minttl"
complete -c $nc -s N -d "shutdown(2) the network socket after EOF on the input"
complete -c $nc -s n -d "Do not do any DNS or service lookups on any specified addresses, hostnames or ports"
complete -c $nc -s O -x -d "Specifies the size of the TCP send buffer"
complete -c $nc -s P -x -d "Specifies a username to present to a proxy server that requires authentication"
complete -c $nc -s p -x -d "Specifies the source port nc should use, subject to privilege restrictions and availability"
complete -c $nc -s q -x -d "after EOF on stdin, wait the specified number of seconds and then quit"
complete -c $nc -s r -d "Specifies that source and/or destination ports should be chosen randomly instead of sequentially within a range or in the order that the system assigns them"
complete -c $nc -s S -d "Enables the RFC 2385 TCP MD5 signature option"
complete -c $nc -s s -x -d "Specifies the IP of the interface which is used to send the packets"
complete -c $nc -s T -x -a "critical inetcontrol lowcost lowdelay netcontrol throughput reliability ef af cs0 cs1 cs2 cs3 cs4 cs5 cs6 cs7" -d "Change IPv4 TOS value"
complete -c $nc -s t -d "Causes nc to send RFC 854 DON'T and WON'T responses to RFC 854 DO and WILL requests"
complete -c $nc -s U -d "Specifies to use UNIX-domain sockets"
complete -c $nc -s u -d "Use UDP instead of the default option of TCP"
complete -c $nc -s V -x -d "Set the routing table to be used"
complete -c $nc -s v -d "Have nc give more verbose output"
complete -c $nc -s W -x -d "Terminate after receiving recvlimit packets from the network"
complete -c $nc -s w -x -d "Connections which cannot be established or are idle timeout after timeout seconds"
function __fish_complete_nc-connect-openbsd
printf "connect\tHTTPS proxy\n"
printf "4\tSOCKS v.4\n"
printf "5\tSOCKS v.5\n"
end
complete -c $nc -s X -x -a "(__fish_complete_nc-connect-openbsd)" -d "Requests that nc should use the specified protocol when talking to the proxy server"
complete -c $nc -s x -x -a "(__fish_print_hostnames)" -d "Requests that nc should connect to destination using a proxy at proxy_address and port"
complete -c $nc -s Z -d "DCCP mode"
complete -c $nc -s z -d "Specifies that nc should just scan for listening daemons, without sending any data to them"
case nc.traditional '*' # fallback to the most restricted one
complete -c $nc -s c -r -d "specify shell commands to exec after connect"
complete -c $nc -s e -r -d "specify filename to exec after connect"
complete -c $nc -s g -x -d "source-routing hop point[s], up to 8"
complete -c $nc -s G -x -d "source-routing pointer: 4, 8, 12, ..."
complete -c $nc -s h -d "display help"
complete -c $nc -s i -x -d "delay interval for lines sent, ports scanned"
complete -c $nc -s l -d "listen mode, for inbound connects"
complete -c $nc -s n -d "numeric-only IP addresses, no DNS"
complete -c $nc -s o -r -d "hex dump of traffic"
complete -c $nc -s p -x -d "local port number (port numbers can be individual or ranges: lo-hi [inclusive])"
complete -c $nc -s q -x -d "after EOF on stdin, wait the specified number of seconds and then quit"
complete -c $nc -s b -d "allow UDP broadcasts"
complete -c $nc -s r -d "randomize local and remote ports"
complete -c $nc -s s -x -d "local source address"
complete -c $nc -s t -d "enable telnet negotiation"
complete -c $nc -s u -d "UDP mode"
complete -c $nc -s v -d "verbose [use twice to be more verbose]"
complete -c $nc -s w -x -d "timeout for connects and final net reads"
complete -c $nc -s C -d "Send CRLF as line-ending"
complete -c $nc -s z -d "zero-I/O mode [used for scanning]"
complete -c $nc -s T -x -a "Minimize-Delay Maximize-Throughput Maximize-Reliability Minimize-Cost" -x -d "set TOS flag"
end
end