OPC.run OPC.run 助跑超级个体

网络工具

curl、wget、ping、netstat 是 CLI 中调试网络问题的四大核心工具。

网络工具

curl:HTTP 请求瑞士军刀

# GET 请求
curl https://api.example.com/users

# 显示响应头
curl -I https://example.com

# POST 请求
curl -X POST https://api.example.com/users \
  -H "Content-Type: application/json" \
  -d '{"name":"Alice","age":30}'

# 下载文件
curl -o file.zip https://example.com/file.zip

# 带认证
curl -u username:password https://api.example.com

wget:文件下载

wget https://example.com/file.zip              # 下载
wget -O custom-name.zip https://example.com/f  # 指定文件名
wget -r https://example.com/docs/              # 递归下载
wget -c https://example.com/large.iso          # 断点续传

ping:测试连通性

ping google.com          # 测试网络连通
ping -c 5 google.com     # 只发 5 个包
ping -t 2 192.168.1.1    # 超时 2 秒

netstat / ss:端口查看

# 查看哪些端口在监听
netstat -tlnp
ss -tlnp                 # 更现代的替代

# 查看某个端口
ss -tlnp | grep 8080

实用场景

# 测试 API 是否正常
curl -s https://api.example.com/health | jq .

# 下载并解压
curl -L https://example.com/app.tar.gz | tar xz

# 测速
wget --spider https://cdn.example.com/large-file.iso

curl 是 API 调试的第一工具,每个开发者都应该熟练掌握。

← 上一课 下一课 →