windows网络调试


ping

ping: 测试网络连接情况

  • -n:要发送的回显请求数
  • -t:ping 主机直到中断
  • -i:生存时间ttl
  • -6:IPv6

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:显示路由信息
$ netstat -ano -p tcp
Active Connections

  Proto  Local Address          Foreign Address        State           PID
  TCP    0.0.0.0:21             0.0.0.0:0              LISTENING       4896
  TCP    0.0.0.0:135            0.0.0.0:0              LISTENING       1032
  TCP    0.0.0.0:445            0.0.0.0:0              LISTENING       4
  TCP    0.0.0.0:902            0.0.0.0:0              LISTENING       10388
  TCP    0.0.0.0:912            0.0.0.0:0              LISTENING       10388
  TCP    0.0.0.0:1080           0.0.0.0:0              LISTENING       11476
  TCP    0.0.0.0:2425           0.0.0.0:0              LISTENING       7728
  TCP    0.0.0.0:5040           0.0.0.0:0              LISTENING       7940
  TCP    0.0.0.0:5357           0.0.0.0:0              LISTENING       4
# 查询5037端口占用:
$ netstat -ano | findstr 5037
# 找到对应进程
$ tasklist | findstr 34212
# 通过PID或者进程名杀死进程:
$ taskkill -pid 34212 -f -t # taskkill /pid 34212 /f /t
$ taskkill -f -im adb.exe # taskkill /f /im adb.exe

网卡信息

$ ipconfig
$ ipconfig /all
$ ipconfig /flushdns
$ netsh interface ipv4 show config
$ netsh interface ipv6 show config
$ wmic nic list brief
# 无线网卡信息
$ netsh wlan show interface
# 断开无线WiFi:
$ netsh wlan disconnect
# 更多netsh wlan命令:
$ netsh wlan /?

The following commands are available:

Commands in this context:
?              - Displays a list of commands.
add            - Adds a configuration entry to a table.
connect        - Connects to a wireless network.
delete         - Deletes a configuration entry from a table.
disconnect     - Disconnects from a wireless network.
dump           - Displays a configuration script.
export         - Saves WLAN profiles to XML files.
help           - Displays a list of commands.
IHV            - Commands for IHV logging.
refresh        - Refresh hosted network settings.
reportissues   - Generate WLAN smart trace report.
set            - Sets configuration information.
show           - Displays information.
start          - Start hosted network.
stop           - Stop hosted network.

路由相关 route

  • -p:添加永久路由
  • Destination: 指定该路由的网络目标。
  • mask:当添加一个网络路由时,需要使用网络掩码。
  • gw:路由数据包通过网关。注意,你指定的网关必须能够达到。
  • metric:设置路由跳数。

    # ipv4
    $ route -p add 23.23.23.0 mask 255.255.255.0 192.168.97.60
    route delete 23.23.23.0
    # ipv6
    $ netsh interface ipv6 add/del route 2001::/64 "Local Area Connection 2" 2001::2

    查看路由表

    $ netstat -r
    $ route print
    $ route print -4
    $ route print -6
    $ netsh interface ipv4 show route
    $ netsh interface ipv6 show route

    禁用启用网卡

    $ netsh interface set interface eth0 disabled # 禁用网卡
    $ netsh interface set interface name="接口名称" admin=DISABLE
    
    $ netsh interface set interface eth0 enabled #启用网卡
    $ netsh interface set interface name="接口名称" admin=ENABLE
    
    $ netsh interface ipv6 set interface name="接口名称"  disable/enable
    
    $ netsh interface show interface #显示接口

    释放、更新地址

    # ipv4
    $ ipconfig /release
    $ ipconfig /renew
    # ipv6
    $ ipconfig /release6
    $ ipconfig /renew6

    添加、删除IP地址

    # ipv4
    $ netsh interface ip add address "本地连接" 192.168.1.100 255.255.255.0
    $ netsh interface ip delete address "本地连接" 192.168.1.100
    ## 设置静态IP地址
    $ netsh interface ip set address name="eth1" source=static address=192.168.5.125 mask=255.255.255.0
    
    # ipv6
    $ netsh interface ipv6 delete address 本地连接 2001::1
    $ netsh interface ipv6 add/del address 本地连接 2001::1
    

    nslookup DNS查询工具

  • [目标主机或IP地址] 你想查询的目标主机或 IP 地址。
  • -type=recordType: 查询指定类型的DNS记录,例如A(IPv4地址)、AAAA(IPv6地址)、MX(邮件交换器)、CNAME(别名记录)、TXT(文本记录)等。
  • 直接在命令提示符窗口输入 nslookup 并按下回车键,进入交互式模式。输入 exit 或 quit 退出交互式模式。

    tracert

  • [目标主机或IP地址] 你想追踪的目标主机或服务器的域名或 IP 地址。
  • -d: 使用目标的IP地址而不是域名。
  • -h maximumHops: 设置最大跳数,默认是30。
  • -w timeout: 设置等待目标地址回复的超时时间,单位是毫秒,默认值是4000毫秒。
  • -4: 强制使用IPv4。
  • -6: 强制使用IPv6。

    PowerShell 的 Test-NetConnection:

  • 使用 PowerShell 中的 Test-NetConnection cmdlet 通过 TCP 或 UDP 协议进行网络连接测试。
  • 示例:Test-NetConnection www.google.com -Port 80 通过 TCP 协议测试到 www.google.com 上的 HTTP 端口 80 的连接。

    重置winsock

  • netsh winsock reset catalog
  • netsh int ip reset reset.log

声明:渣渣的学习日记|版权所有,违者必究|如未注明,均为原创|本网站采用BY-NC-SA协议进行授权

转载:转载请注明原文链接 - windows网络调试


Carpe Diem and Do what I like