[modules/nic] Using iw to find out whats the SSID name

This commit is contained in:
Marvin Steadfast 2020-06-30 14:49:43 +02:00
parent e006344dcc
commit 6d9d325eca

View file

@ -12,6 +12,7 @@ Parameters:
* nic.format: Format string (defaults to '{intf} {state} {ip} {ssid}') * nic.format: Format string (defaults to '{intf} {state} {ip} {ssid}')
""" """
import re
import shutil import shutil
import netifaces import netifaces
import subprocess import subprocess
@ -44,7 +45,7 @@ class Module(core.module.Module):
else: else:
self._states["include"].append(state) self._states["include"].append(state)
self._format = self.parameter("format", "{intf} {state} {ip} {ssid}") self._format = self.parameter("format", "{intf} {state} {ip} {ssid}")
self.iwgetid = shutil.which("iwgetid") self.iw = shutil.which("iw")
self._update_widgets(widgets) self._update_widgets(widgets)
def update(self): def update(self):
@ -125,10 +126,13 @@ class Module(core.module.Module):
widget.set("state", state) widget.set("state", state)
def get_ssid(self, intf): def get_ssid(self, intf):
if self._iswlan(intf) and not self._istunnel(intf) and self.iwgetid: if self._iswlan(intf) and not self._istunnel(intf) and self.iw:
return util.cli.execute( ssid = util.cli.execute("{} dev {} link".format(self.iw, intf))
"{} -r {}".format(self.iwgetid, intf), ignore_errors=True found_ssid = re.findall("SSID:\s(.+)", ssid)
) if len(found_ssid) > 0:
return found_ssid[0]
else:
return ""
return "" return ""