def zeroconf_info():
"""zeroconf_info returns a list of tuples of the information about other
zeroconf services on the local network. It does this by creating a
zeroconf.ServiceBrowser and spending 0.25 seconds querying the network for
other services."""
ret_info = []
def on_change(zeroconf, service_type, name, state_change):
if state_change is zeroconfig.ServiceStateChange.Added:
info = zeroconf.get_service_info(service_type, name)
if info:
address = "{}".format(socket.inet_ntoa(info.address))
props = str(info.properties.items())
item = ServerInfo(str(info.server), address, info.port, props)
ret_info.append(item)
zc = zeroconfig.Zeroconf()
browser = zeroconfig.ServiceBrowser(
zc, "_defusedivision._tcp.local.", handlers=[on_change])
sleep(1)
concurrency.concurrent(lambda: zc.close())()
return ret_info
评论列表
文章目录