Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要知道我的 PC 是否通过 WiFi、LAN、VPN 进行通信……我的应用程序造成了沉重的网络负载,在某些情况下启动毫无意义,这就是为什么我需要知道 PC 通过哪个连接与世界通信…… </p>
一种蛮力方式可能有效:
这个想法是解析 ipconfig/ifconfig 输出。
首先获取候选的 UP 接口列表(例如 lan0、wlan0)。然后发送一些数据(例如 ping google.com),比较发送数据前后的 Rx 数据包和 tx 数据包数量,您应该可以知道正在使用哪个接口。
希望这可以帮助。