Skip to content
Snippets Groups Projects
Commit 499ad77a authored by Jess Ward's avatar Jess Ward
Browse files

Get device mac addresses

parent f03f39fb
No related branches found
Tags boomtown-v1
No related merge requests found
......@@ -2,7 +2,7 @@ from zeroconf import ServiceBrowser, Zeroconf
import snapcast.control
import asyncio
import ipaddress
# import netifaces
import netifaces
class Scanner:
......@@ -43,11 +43,31 @@ def get_snapcast_server():
def get_mac_addresses():
pass
'''Get list of all IPv4 MAC addresses for this device.'''
def contains_loopback(af_inet_addresses):
'''Check if list of IPv4 addresses contains loopback.'''
for ip in af_inet_addresses:
if ipaddress.IPv4Address(ip['addr']).is_loopback:
return True
return False
mac_addresses = []
for interface in netifaces.interfaces():
addresses = netifaces.ifaddresses(interface)
# Skip interfaces without an IPv4 address
if netifaces.AF_INET not in addresses:
continue
if contains_loopback(addresses[netifaces.AF_INET]):
continue
for mac in addresses[netifaces.AF_LINK]:
# Add to list if address has 'addr' key
if mac['addr']:
mac_addresses.append(mac['addr'])
return mac_addresses
def get_snapcast_client(server):
'''scan through list of clients to find correct one'''
'''Scan through list of clients to find correct one.'''
for client in server.clients:
print(client.name)
print(client.identifier)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment