connect to somewhere: netcat [-options] hostname port[s] [ports] …
listen for inbound: netcat -l -p port [-options] [hostname] [port]
options:
-g gateway source-routing hop point[s], up to 8
-G num source-routing pointer: 4, 8, 12, …
-h this cruft
-i secs delay interval for lines sent, ports scanned
-l listen mode, for inbound connects
-n numeric-only IP addresses, no DNS
-o file hex dump of traffic
-p port local port number
-r randomize local and remote ports
-s addr local source address
-t answer TELNET negotiation
-u UDP mode
-v verbose [use twice to be more verbose]
-w secs timeout for connects and final net reads
-z zero-I/O mode [used for scanning]
port numbers can be individual or ranges: lo-hi [inclusive]
基本格式:nc [-options] hostname port[s] [ports] …
nc -l -p port [options] [hostname] [port]
-d 后臺模式
-e prog 程序重定向,一旦連接,就執(zhí)行 [危險!!]
-g gateway source-routing hop point[s], up to 8
-G num source-routing pointer: 4, 8, 12, …
-h 幫助信息
-i secs 延時的間隔
-l 監(jiān)聽模式,用于入站連接
-L 連接關(guān)閉后,仍然繼續(xù)監(jiān)聽
-n 指定數(shù)字的IP地址,不能用hostname
-o file 記錄16進制的傳輸
-p port 本地端口號
-r 隨機本地及遠程端口
-s addr 本地源地址
-t 使用TELNET交互方式
-u UDP模式
-v 詳細輸出–用兩個-v可得到更詳細的內(nèi)容
-w secs timeout的時間
-z 將輸入輸出關(guān)掉–用于掃描時
端口的表示方法可寫為M-N的范圍格式。
測試udp連接方法
a機器上運行:
nc -ul 1080
或:netcat -ul -p 1080
#使用udp模式監(jiān)聽1080 端口
b機器上運行:
nc -u x.x.x.x 1080
或:netcat -u x.x.x.x 1080
#使用udp模式向該ip的1080端口發(fā)送信息。
效果如圖,在任意一邊輸入內(nèi)容,另一邊則會收到相應(yīng)內(nèi)容,以此就可以測試該端口的udp連接是否通常。