# 12.4 命令行工具netcat

命令行工具`nc(1)`，全称`netcat(1)`，在测试TCP/IP的客户端和服务端时非常便利。本节将介绍它的一些常见用法。

````
> ```shell
> nc 10.10.1.123 1234
>
````

命令行工具`nc(1)`默认使用TCP协议。如果使用UDP协议，可以在执行`nc(1)`命令时携带`-u`参数。

如果要使用`netcat(1)`模拟服务器，可以携带`-l`参数，`netcat(1)`将监听指定端口号的连接。

如果希望`netcat(1)`生成详细的输出，可以使用`-v`和`-vv`参数，这些输出对排查网络连接故障提供了很大的便利。

`netcat(1)`不仅可以测试HTTP应用程序，在第13章*网络编程 - 构建服务器与客户端*中，它同样可以灵活的使用，用于开发TCP和UDP协议的客户机和服务器。在本章中后续的一个例子中，`` `netcat(1) ``将作为案例使用。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wskdsgcf.gitbook.io/mastering-go-zh-cn/12.0/12.4.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
