I need to get the wifi unique ID. SSID is not safe as you can have different wifis with the same name, so I wen to find the MAC address of the router. So far I use arp to get this info but I found a wifi where the MAC address seems to change over time. Is this function the right one to retrieve the MAC adress of the wifi router ?
def get_wifi_info(self):
result = subprocess.run(["iwgetid"], capture_output=True, text=True)
ssid = result.stdout.split('"')[1]
arp_output = subprocess.check_output(["/usr/sbin/arp", "-a"]).decode("utf-8")
mac_pattern = re.compile(r"..:..:..:..:..:..")
mac_address = mac_pattern.findall(arp_output)
return ssid, mac_address[0]
I am on Raspbian 11. Thanks for your help.