【问题标题】:Python: is a given network interface wifi or ethernet?Python:给定的网络接口是wifi还是以太网?
【发布时间】:2013-05-07 15:09:37
【问题描述】:

有没有办法从 Python 中知道给定(并已连接)网络接口wifi 还是 以太网

模块inetfaces 提供了可用网络接口和相应地址的列表,但仅此而已。

【问题讨论】:

标签: python wifi ethernet network-interface


【解决方案1】:

使用pyroute2.IW(类似的脚本在示例目录中):

import sys
from pyroute2 import IW
from pyroute2 import IPRoute
from pyroute2.netlink import NetlinkError

ip = IPRoute()
iw = IW()
index = ip.link_lookup(ifname=sys.argv[1])[0]
try:
    iw.get_interface_by_ifindex(index)
    print("wireless interface")
except NetlinkError as e:
    if e.code == 19:  # 19 'No such device'
        print("not a wireless interface")
finally:
    iw.close()
    ip.close()

【讨论】:

    【解决方案2】:

    您可以使用 python scapy 模块。

    from scapy.all import *
    print(get_windows_if_list())
    

    【讨论】:

      猜你喜欢
      • 2019-08-18
      • 1970-01-01
      • 2012-07-30
      • 2011-11-12
      • 1970-01-01
      • 1970-01-01
      • 2014-03-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多