最終更新:2023-08-29 (火) 03:04:55 (241d)  

nc
Top / nc

netcat

arbitrary TCP and UDP connections and listens

使い方

  • nc <host> <port>

オプション

  • -qquit after EOF on stdin and delay of secs
    -uUDP mode
    -lListen mode, for inbound connects

リッスンモード

  • デフォルトはTCP
  • -pオプションを指定しない場合は、空いているポート番号が自動的に選択される

種類

  • オリジナル版netcat (netcat-traditional) (1995)
  • OpenBSD版netcat
  • Nmap付属netcat

動作

  • 標準入力(stdin)からデータストリームを受け取る
  • そのデータストリームを引数で指定された接続先ホストにそのまま送り込む
  • 接続先ホストからの応答を、そのまま標準出力(stdout)に出力する

メモ

  • DESCRIPTION
         The nc (or netcat) utility is used for just about anything under the sun
         involving TCP, UDP, or UNIX-domain sockets.  It can open TCP connections,
         send UDP packets, listen on arbitrary TCP and UDP ports, do port scan‐
         ning, and deal with both IPv4 and IPv6.  Unlike telnet(1), nc scripts
         nicely, and separates error messages onto standard error instead of send‐
         ing them to standard output, as telnet(1) does with some.
    
         Common uses include:
    
               ·   simple TCP proxies
               ·   shell-script based HTTP clients and servers
               ·   network daemon testing
               ·   a SOCKS or HTTP ProxyCommand for ssh(1)
               ·   and much, much more

help

  • OpenBSD netcat (Debian patchlevel 1.206-1ubuntu1)
    usage: nc [-46CDdFhklNnrStUuvZz] [-I length] [-i interval] [-M ttl]
    	  [-m minttl] [-O length] [-P proxy_username] [-p source_port]
    	  [-q seconds] [-s source] [-T keyword] [-V rtable] [-W recvlimit] [-w timeout]
    	  [-X proxy_protocol] [-x proxy_address[:port]] 	  [destination] [port]
    	Command Summary:
    		-4		Use IPv4
    		-6		Use IPv6
    		-b		Allow broadcast
    		-C		Send CRLF as line-ending
    		-D		Enable the debug socket option
    		-d		Detach from stdin
    		-F		Pass socket fd
    		-h		This help text
    		-I length	TCP receive buffer length
    		-i interval	Delay interval for lines sent, ports scanned
    		-k		Keep inbound sockets open for multiple connects
    		-l		Listen mode, for inbound connects
    		-M ttl		Outgoing TTL / Hop Limit
    		-m minttl	Minimum incoming TTL / Hop Limit
    		-N		Shutdown the network socket after EOF on stdin
    		-n		Suppress name/port resolutions
    		-O length	TCP send buffer length
    		-P proxyuser	Username for proxy authentication
    		-p port		Specify local port for remote connects
    		-q secs		quit after EOF on stdin and delay of secs
    		-r		Randomize remote ports
    		-S		Enable the TCP MD5 signature option
    		-s source	Local source address
    		-T keyword	TOS value
    		-t		Answer TELNET negotiation
    		-U		Use UNIX domain socket
    		-u		UDP mode
    		-V rtable	Specify alternate routing table
    		-v		Verbose
    		-W recvlimit	Terminate after receiving a number of packets
    		-w timeout	Timeout for connects and final net reads
    		-X proto	Proxy protocol: "4", "5" (SOCKS) or "connect"
    		-x addr[:port]	Specify proxy address and port
    		-Z		DCCP mode
    		-z		Zero-I/O mode [used for scanning]
    	Port numbers can be individual or ranges: lo-hi [inclusive]

関連

  • Linux/bin/nc? > Linux/etc/alternatives/nc? -> Linux/bin/nc.openbsd?

参考

関連