nc (netcat)
ネットワーク
書き方
nc [-lv] <host> <port>TCP や UDP を素のままつないで、ポートが答えるかを見たり二台の間に管を通したりします。名前が同じで互換のない版が三つ(OpenBSD・GNU・Nmap の ncat)あり、`-z` や `-p` が無いこともあります。
よく使うオプション
| オプション | 意味 |
|---|---|
| -l | Listen instead of connecting. On GNU netcat you also need -p <port>. |
| -v | Say what happened, which is the whole point when testing a port. |
| -z | Scan without sending data. OpenBSD/macOS nc only; GNU netcat has no -z. |
| -w 3 | Give up after three seconds instead of hanging. |
| -u | UDP instead of TCP. |
| -4 / -6 | Force one address family. |
例
nc -zv example.com 443Is the port open? Works on macOS and OpenBSD netcat.
nc -l 1234 # then on the other host: nc <host> 1234A raw two-way pipe for a quick test.
nc -l 1234 > incoming.binReceive a file that the other side sends with nc host 1234 < file.
つながらないとき、どこまで行けたのかを絞ります — 名前が引けないのか、経路がないのか、ポートが閉じているのか。
読み方
- 角括弧 [ ] は省いてよい部分です。
- 三点 … は複数並べられるという意味です。
- オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。
よくある質問
Q. nc (netcat) は何をしますか。
TCP や UDP を素のままつないで、ポートが答えるかを見たり二台の間に管を通したりします。名前が同じで互換のない版が三つ(OpenBSD・GNU・Nmap の ncat)あり、`-z` や `-p` が無いこともあります。
Q. どう打ちますか。
nc [-lv] <host> <port> — 角括弧は省いてよい部分です。
Q. よく使うオプションはいくつですか。
ここにまとめたのは6個です。全部は man nc にあります。このコマンドはネットワークの仲間です。
関連するコマンド
man ページ: man nc-(netcat)