尝试用这小段代码来了解断开 WiFi 连接后 Windows 上的默认路由发生了什么:
echo "=> Clearing the destinationcache cache ..."
gsudo.exe netsh interface ip delete destinationcache
echo '=> Printing default routes via "route print" ...'
route print | sls "Netmask|0.0.0.0.*0.0.0.0"
echo ''
echo '=> Printing default routes via "Get-NetRoute -DestinationPrefix 0.0.0.0/0" ...'
Get-NetRoute -DestinationPrefix 0.0.0.0/0 | Out-String -Stream
echo '=> Printing default routes via "netsh int ip sh route" ...'
echo ''
netsh int ip sh route | sls "Prefix|0.0.0.0/0"
我得到了这个输出:
=> Clearing the destinationcache cache ...
Ok.
=> Printing default routes via "route print" ...
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 10.20.24.1 10.20.24.14 35
=> Printing default routes via "Get-NetRoute -DestinationPrefix 0.0.0.0/0" ...
ifIndex DestinationPrefix NextHop RouteMetric ifMetric PolicyStore
------- ----------------- ------- ----------- -------- -----------
12 0.0.0.0/0 172.20.88.1 0 40 ActiveStore
24 0.0.0.0/0 10.20.24.1 0 35 ActiveStore
=> Printing default routes via "netsh int ip sh route" ...
Publish Type Met Prefix Idx Gateway/Interface Name
No Manual 0 0.0.0.0/0 24 10.20.24.1
No Manual 0 0.0.0.0/0 12 172.20.88.1
Get-NetRoute -DestinationPrefix 0.0.0.0/0
断开 WiFi 网络并删除 destinationcache 缓存后,和也应该只有一行netsh int ip sh route
。
这里发生了什么 ?