mirror of
https://github.com/vvzvlad/vestasync.git
synced 2024-12-25 19:51:00 +03:00
add real-time search
This commit is contained in:
parent
00fdfb6298
commit
1dc2a8594a
@ -15,6 +15,9 @@ class MyListener:
|
|||||||
def add_service(self, zeroconf, type, name):
|
def add_service(self, zeroconf, type, name):
|
||||||
info = zeroconf.get_service_info(type, name)
|
info = zeroconf.get_service_info(type, name)
|
||||||
self.found_services.append(info)
|
self.found_services.append(info)
|
||||||
|
print(f"Name: {info.name}")
|
||||||
|
print(f"IP: {info.parsed_addresses()[0]}")
|
||||||
|
print("")
|
||||||
|
|
||||||
def update_service(self, zeroconf, type, name):
|
def update_service(self, zeroconf, type, name):
|
||||||
pass
|
pass
|
||||||
@ -24,25 +27,14 @@ def main():
|
|||||||
listener = MyListener()
|
listener = MyListener()
|
||||||
browser = ServiceBrowser(zeroconf, "_workstation._tcp.local.", listener)
|
browser = ServiceBrowser(zeroconf, "_workstation._tcp.local.", listener)
|
||||||
|
|
||||||
# Устанавливаем время ожидания и ждем, пока не найдутся все службы
|
try:
|
||||||
timeout = 15
|
while True:
|
||||||
wait_event = Event()
|
time.sleep(0.1)
|
||||||
wait_event.wait(timeout)
|
except KeyboardInterrupt:
|
||||||
|
pass
|
||||||
# Закрываем браузер служб и освобождаем ресурсы
|
finally:
|
||||||
browser.cancel()
|
browser.cancel()
|
||||||
zeroconf.close()
|
zeroconf.close()
|
||||||
|
|
||||||
# Выводим список найденных служб
|
|
||||||
print("Found services:")
|
|
||||||
for service in listener.found_services:
|
|
||||||
print(f"Name: {service.name}")
|
|
||||||
print(f"IP: {service.parsed_addresses()[0]}")
|
|
||||||
print("")
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user