forked from nazirlouis/ada_v2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_mdns.py
More file actions
42 lines (34 loc) · 1.23 KB
/
Copy pathdebug_mdns.py
File metadata and controls
42 lines (34 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import asyncio
from zeroconf import Zeroconf, ServiceBrowser, ServiceListener
class MyListener(ServiceListener):
def add_service(self, zc: Zeroconf, type_: str, name: str) -> None:
info = zc.get_service_info(type_, name)
if info:
addresses = info.parsed_addresses()
print(f"FOUND: {name} ({type_})")
print(f" - Host: {addresses[0] if addresses else 'Unknown'}:{info.port}")
print(f" - Properties: {info.properties}")
def remove_service(self, zc: Zeroconf, type_: str, name: str) -> None:
pass
def update_service(self, zc: Zeroconf, type_: str, name: str) -> None:
pass
async def scan():
zeroconf = Zeroconf()
listener = MyListener()
print("Scanning for common printer services...")
services = [
"_octoprint._tcp.local.",
"_moonraker._tcp.local.",
"_klipper._tcp.local.",
"_http._tcp.local.",
"_ipp._tcp.local.",
"_printer._tcp.local."
]
browsers = []
for s in services:
browsers.append(ServiceBrowser(zeroconf, s, listener))
print("Listening for 10 seconds...")
await asyncio.sleep(10)
zeroconf.close()
if __name__ == "__main__":
asyncio.run(scan())