Created an embryo for hardware detection. Supports detecting WiFi and UEFI. This fixes #44 and is a start for #82.
This commit is contained in:
parent
5c696c4bc1
commit
68adb3108f
|
|
@ -12,3 +12,4 @@ from .lib.services import *
|
||||||
from .lib.packages import *
|
from .lib.packages import *
|
||||||
from .lib.output import *
|
from .lib.output import *
|
||||||
from .lib.storage import *
|
from .lib.storage import *
|
||||||
|
from .lib.hardware import *
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
import os
|
||||||
|
from .networking import list_interfaces, enrichIfaceTypes
|
||||||
|
|
||||||
|
def hasWifi():
|
||||||
|
if 'WIRELESS' in enrichIfaceTypes(list_interfaces().values()).values():
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def hasUEFI():
|
||||||
|
return os.path.isdir('/sys/firmware/efi')
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
|
import os
|
||||||
import fcntl
|
import fcntl
|
||||||
import socket
|
import socket
|
||||||
import struct
|
import struct
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
|
|
||||||
def getHwAddr(ifname):
|
def getHwAddr(ifname):
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
info = fcntl.ioctl(s.fileno(), 0x8927, struct.pack('256s', bytes(ifname, 'utf-8')[:15]))
|
info = fcntl.ioctl(s.fileno(), 0x8927, struct.pack('256s', bytes(ifname, 'utf-8')[:15]))
|
||||||
|
|
@ -19,5 +19,22 @@ def list_interfaces(skip_loopback=True):
|
||||||
interfaces[mac] = iface
|
interfaces[mac] = iface
|
||||||
return interfaces
|
return interfaces
|
||||||
|
|
||||||
|
def enrichIfaceTypes(interfaces :dict):
|
||||||
|
result = {}
|
||||||
|
for iface in interfaces:
|
||||||
|
if os.path.isdir(f"/sys/class/net/{iface}/bridge/"):
|
||||||
|
result[iface] = 'BRIDGE'
|
||||||
|
elif os.path.isfile(f"/sys/class/net/{iface}/tun_flags"):
|
||||||
|
# ethtool -i {iface}
|
||||||
|
result[iface] = 'TUN/TAP'
|
||||||
|
elif os.path.isdir(f"/sys/class/net/{iface}/device"):
|
||||||
|
if os.path.isdir(f"/sys/class/net/{iface}/wireless/"):
|
||||||
|
result[iface] = 'WIRELESS'
|
||||||
|
else:
|
||||||
|
result[iface] = 'PHYSICAL'
|
||||||
|
else:
|
||||||
|
result[iface] = 'UNKNOWN'
|
||||||
|
return result
|
||||||
|
|
||||||
def get_interface_from_mac(mac):
|
def get_interface_from_mac(mac):
|
||||||
return list_interfaces().get(mac.lower(), None)
|
return list_interfaces().get(mac.lower(), None)
|
||||||
Loading…
Reference in New Issue