网络命令
查看 IP 与网卡
ipconfig :: 全部网卡信息
ipconfig /all :: 详细(MAC、DHCP、网关、DNS)
ipconfig /flushdns :: 刷新 DNS 缓存
ipconfig /renew :: 重新获取 DHCP 地址
getmac :: 查看本机网卡 MAC
netstat -rn :: 查看路由表
route print :: 同上(路由表)
PowerShell 等价:
Get-NetIPAddress -AddressFamily IPv4 # IP
Get-NetAdapter # 网卡列表
Get-NetAdapter | Select-Object Name, MacAddress # MAC
Get-NetRoute # 路由表
连通性与排障
ping baidu.com :: 测试连通
ping -n 4 baidu.com :: 指定次数
ping -t baidu.com :: 持续 ping(Ctrl+C 停止,看丢包)
tracert baidu.com :: 追踪路由路径
pathping baidu.com :: 聚焦网络质量丢包(较慢)
nslookup baidu.com :: 查询 DNS
nslookup -type=mx baidu.com :: 查询 MX 记录
| 命令 | 用途 |
|---|---|
ping | 连通性、丢包、延迟 |
tracert | 路径中在哪一跳断了 |
pathping | 每跳丢包/延迟统计 |
nslookup | DNS 解析是否正常 |
telnet | 测试 TCP 端口连通(需安装可选功能) |
端口与连接
netstat -ano :: 全部连接 + PID
netstat -an | findstr :8080 :: 8080 端口连接
netstat -ano | findstr "LISTENING" :: 所有监听端口
netstat -ano | findstr :80 :: 查 80 端口占用→PID→tasklist
netstat -b :: 显示进程名(需管理员)
PowerShell:
Get-NetTCPConnection -State Listen | Select LocalPort, OwningProcess
Get-NetTCPConnection -LocalPort 8080
Test-NetConnection baidu.com -Port 443 # 端口连通测试(telnet 替代)
排查外网访问不了服务:
ping→telnet IP 端口→ 检查本机监听 → 防火墙。
HTTP 请求
curl -I https://www.baidu.com :: 只看响应头(Win10+ 自带 curl)
curl -O https://xxx/install.exe :: 下载保存原文件名
curl -o out.txt url :: 保存为指定文件名
curl -x http://127.0.0.1:7890 url :: 走代理
PowerShell 7+ 自带 curl 别名指向 curl.exe;老版本 curl 是 Invoke-WebRequest 的别名(行为不同)。建议在 PowerShell 中显式用 curl.exe,或使用:
Invoke-WebRequest -Uri url -OutFile out.exe
Invoke-RestMethod -Uri url -Method Post -Body $json -ContentType "application/json"
防火墙(netsh,需管理员)
netsh advfirewall show allprofiles :: 查看防火墙状态
netsh advfirewall set allprofiles state off :: 关防火墙 ⚠️
netsh advfirewall firewall add rule name="Allow 8080" dir=in action=allow protocol=tcp localport=8080
netsh advfirewall firewall delete rule name="Allow 8080"
netsh advfirewall firewall show rule name=all :: 列出全部规则
WiFi 相关
netsh wlan show profiles :: 已保存的 WiFi
netsh wlan show profile name="xxx" key=clear :: 查看 WiFi 密码(管理员)
netsh wlan show interfaces :: 当前连接状态
netsh wlan connect name="xxx" :: 连接指定 WiFi
远程桌面与文件共享
mstsc :: 打开远程桌面并可选 /v:host 直连
mstsc /v:192.168.1.10 :: 远程桌面到指定 IP
net use z: \\192.168.1.10\share /user:user pass :: 映射网络驱动器
net use z: /delete :: 删除映射
psexec \\host cmd :: 远程执行命令(Sysinternals 工具)
其他常用
hostname :: 查看主机名
net share :: 查看共享文件夹
net user :: 查看用户(本地)
systeminfo :: 系统信息(详见系统篇)
curl --interface ;; 指定网卡出网(curl 高级用法,详见官方文档)