1

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.

Ricky Robinson
  • 21,798
  • 42
  • 129
  • 185
  • See: http://stackoverflow.com/questions/14648941/how-to-know-if-mac-address-is-attached-to-wireless-card-or-ethernet-card – Dhara May 07 '13 at 15:19
  • http://stackoverflow.com/questions/5281341/get-local-network-interface-addresses-using-only-proc – gsmaker May 07 '13 at 15:20
  • Actually, I would run in a separate process `iwconfig $interfaceName` and parse the result. Would this be ok? – Ricky Robinson May 07 '13 at 15:26

2 Answers2

2

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()
svinota
  • 779
  • 8
  • 10
0

You can use the python scapy module.

from scapy.all import *
print(get_windows_if_list())
Ajay Kumar K K
  • 321
  • 2
  • 7