Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
from zeroconf import ServiceBrowser, Zeroconf
class MycroftListener(object):
def __init__(self):
self.devices = {}
def remove_service(self, zeroconf, type, name):
print("Service %s removed" % (name,))
self.devices.pop(name)
def add_service(self, zeroconf, dev_type, name):
info = zeroconf.get_service_info(dev_type, name)
self.devices[name] = info
ip = [i for i in info.address]
port = info.port
addr = '{}.{}.{}.{}'.format(ip[0], ip[1], ip[2], ip[3], port)
print('{} at {}:{}'.format(name, addr, port))
zeroconf = Zeroconf()
listener = MycroftListener()
browser = ServiceBrowser(zeroconf, "_mycroft._tcp.local.", listener)
try:
input("Press enter to exit...\n\n")
finally:
zeroconf.close()
<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">Mycroft</name>
<service>
<type>_mycroft._tcp</type>
<port>8181</port>
</service>
</service-group>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment