Run:
python3 -m venv .venv
venv/bin/activate
pip3 install -r requirements.txt
python3 app.py
from zeroconf import ServiceBrowser, ServiceListener, Zeroconf, ZeroconfServiceTypes | |
class MyListener(ServiceListener): | |
def update_service(self, zc: Zeroconf, type_: str, name: str) -> None: | |
info = zc.get_service_info(type_, name) | |
print("Updated: \t", format_info(info)) | |
def remove_service(self, zc: Zeroconf, type_: str, name: str) -> None: | |
info = zc.get_service_info(type_, name) | |
print("Removed: \t", format_info(info)) | |
def add_service(self, zc: Zeroconf, type_: str, name: str) -> None: | |
info = zc.get_service_info(type_, name) | |
print("Added: \t\t", format_info(info)) | |
def format_info(info): | |
if info is None: | |
return "None" | |
str = "Server: \t" + info.server + ",\t\tIP: \t" + info.parsed_addresses()[0] | |
return str | |
zeroconf = Zeroconf() | |
listener = MyListener() | |
services = ZeroconfServiceTypes.find() | |
#map services into string array | |
services = list(services) | |
browser = ServiceBrowser(zeroconf, services, listener) | |
try: | |
input("Press enter to exit...\n\n") | |
finally: | |
zeroconf.close() |
zeroconf==0.74.0 |