Is there a way, from within Python, to know if a given (and connected) network interface is wifi or Ethernet?
The module inetfaces
provides a list of network interfaces available and corresponding addresses, but nothing more.
Is there a way, from within Python, to know if a given (and connected) network interface is wifi or Ethernet?
The module inetfaces
provides a list of network interfaces available and corresponding addresses, but nothing more.
With pyroute2.IW (a script like that is in the examples directory):
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()
You can use the python scapy module.
from scapy.all import *
print(get_windows_if_list())