ping
ping: 测试网络连接情况
-n
:要发送的回显请求数-t
:ping 主机直到中断-i
:生存时间ttl-6
:IPv6
1 | $ ping 192.168.20.8 -n 3 |
网络信息查询
netstat
netstat: 协议统计和当前 TCP/IP 网络连接
-t
列出所有tcp连接-a
:显示所有连接和侦听端口-n
:以数字形式显示地址和端口号-o
:显示进程 ID-p proto
:显示指定的协议的连接,TCP、UDP、TCPv6 或 UDPv6-s
:显示每个协议的统计。默认情况下,显示IP、IPv6、ICMP、ICMPv6、TCP、TCPv6、UDP 和 UDPv6的统计信息,可使用-p
选项指定协议。-e
:显示以太网统计。此选项可以与 -s 选项结合使用。-r
:显示路由信息
1 | $ netstat -ano -p tcp |
查询5037端口占用:
1 | $ netstat -ano | findstr 5037 |
找到对应进程(也可以在任务管理器中查看):1
2$ tasklist | findstr 34212
adb.exe 34212 Console 1 10,692 K
通过PID或者进程名杀死进程:1
2$ taskkill -pid 34212 -f -t # taskkill /pid 34212 /f /t
$ taskkill -f -im adb.exe # taskkill /f /im adb.exe
网卡信息
1 | $ ipconfig |
查看IP地址:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15$ netsh interface ip show address WAN
Configuration for interface "WAN"
DHCP enabled: Yes
IP Address: 192.168.3.98
Subnet Prefix: 192.168.3.0/24 (mask 255.255.255.0)
Default Gateway: 192.168.3.252
Gateway Metric: 0
InterfaceMetric: 25
$
$ netsh interface ipv4 show dnsservers WAN
Configuration for interface "WAN"
DNS servers configured through DHCP: 192.168.3.252
Register with which suffix: Primary only
更多命令:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28$ netsh interface ipv4 show /?
The following commands are available:
Commands in this context:
show addresses - Shows IP address configurations.
show compartments - Shows compartment parameters.
show config - Displays IP address and additional information.
show destinationcache - Shows destination cache entries.
show dnsservers - Displays the DNS server addresses.
show dynamicportrange - Shows dynamic port range configuration parameters.
show excludedportrange - Shows all excluded port ranges.
show global - Shows global configuration parameters.
show icmpstats - Displays ICMP statistics.
show interfaces - Shows interface parameters.
show ipaddresses - Shows current IP addresses.
show ipnettomedia - Displays IP net-to-media mappings.
show ipstats - Displays IP statistics.
show joins - Displays multicast groups joined.
show neighbors - Shows neighbor cache entries.
show offload - Displays the offload information.
show route - Shows route table entries.
show subinterfaces - Shows subinterface parameters.
show tcpconnections - Displays TCP connections.
show tcpstats - Displays TCP statistics.
show udpconnections - Displays UDP connections.
show udpstats - Displays UDP statistics.
show winsservers - Displays the WINS server addresses.
无线网卡信息:netsh wlan show interface
1 | $ netsh wlan show interface |
断开无线WiFi:
1 | $ netsh wlan disconnect |
更多netsh wlan
命令:
1 | $ netsh wlan /? |
路由配置
route add [Destination] mask [netmask] [gw] metric [测量值]
- -p:添加永久路由
- Destination: 指定该路由的网络目标。
- mask:当添加一个网络路由时,需要使用网络掩码。
- gw:路由数据包通过网关。注意,你指定的网关必须能够达到。
- metric:设置路由跳数。
1 | # ipv4 |
查看路由表
1 | $ netstat -r |
禁用启用网卡
1 | $ netsh interface set interface eth0 disabled # 禁用网卡 |
通过python脚本自动化控制:1
2import os
os.popen('netsh interface set interface name="接口名称" admin=DISABLE')
释放、更新地址
1 | # ipv4 |
添加、删除IP地址
1 | # ipv4 |
本文标题:Windows 网络管理命令
文章作者:hiyo
文章链接:https://hiyongz.github.io/posts/windows-shell-for-networking-management/
许可协议:本博客文章除特别声明外,均采用CC BY-NC-ND 4.0 许可协议。转载请保留原文链接及作者。