def __init__(self, name=None, host="0.0.0.0", port=22555): # create socket server asyncore.dispatcher.__init__(self) self.create_socket(socket.AF_INET, socket.SOCK_STREAM) self.set_reuse_addr() self.bind((host, port)) self.listen(5) self.remote_clients = [] macstr = "%012X" % uuid.getnode() self.deviceid = ''.join("%s:" % macstr[i:i + 2] for i in range(0, len(macstr), 2))[:-1] self.features = 0x07 # 0x77 on iOS 4.3.1 self.model = "AppleTV2,1" # create avahi service if (name is None): name = "Airplay Service on " + platform.node() self.zeroconf_service = ZeroconfService( name, port=port, stype="_airplay._tcp", text=[ "deviceid=" + self.deviceid, "features=" + hex(self.features), "model=" + self.model ]) # publish avahi service self.zeroconf_service.publish() # do this so we do not block the main thread self.thread = AsyncoreThread(timeout=30) self.thread.is_finished = False self.thread.start() print("AirPlayService running")
def __init__(self, apserver, name=None, host="0.0.0.0", port=22555, index=-1, device_id=None): MultiService.__init__(self) self.apserver = IAirPlayServer(apserver) if device_id: self.deviceid = device_id else: macstr = "%012X" % uuid.getnode() self.deviceid = ''.join("%s:" % macstr[i:i + 2] for i in range(0, len(macstr), 2))[:-1] # 0x77 instead of 0x07 in order to support AirPlay from ordinary apps; # also means that the body for play will be a binary plist. self.features = 0x77 self.model = "AppleTV2,1" # create TCP server TCPServer(port, self.create_site(), 100, interface=host).setServiceParent(self) # create avahi service if (name is None): name = "Airplay Service on " + platform.node() zconf = ZeroconfService(name, port=port, stype="_airplay._tcp", text=["deviceid=" + self.deviceid, "features=" + hex(self.features), "model=" + self.model], index=index) zconf.setServiceParent(self) # for logging self.name_ = name self.host = host self.port = port
def publish_service(): """ Registering and publishing a service using Avahi """ service = ZeroconfService(name=_service_name, stype="_linconnect._tcp", port=int(parser.get('connection', 'port'))) service.publish()
class AirPlayService(asyncore.dispatcher): def __init__(self, name=None, host="0.0.0.0", port=22555): # create socket server asyncore.dispatcher.__init__(self) self.create_socket(socket.AF_INET, socket.SOCK_STREAM) self.set_reuse_addr() self.bind((host, port)) self.listen(5) self.remote_clients = [] macstr = "%012X" % uuid.getnode() self.deviceid = "".join("%s:" % macstr[i : i + 2] for i in range(0, len(macstr), 2))[:-1] self.features = 0x07 # 0x77 on iOS 4.3.1 self.model = "AppleTV2,1" # create avahi service if name is None: name = "Airplay Service on " + platform.node() self.zeroconf_service = ZeroconfService( name, port=port, stype="_airplay._tcp", text=["deviceid=" + self.deviceid, "features=" + hex(self.features), "model=" + self.model], ) # publish avahi service self.zeroconf_service.publish() # do this so we do not block the main thread self.thread = AsyncoreThread(timeout=30) self.thread.is_finished = False self.thread.start() print "AirPlayService running" def handle_accept(self): pair = self.accept() if pair is None: pass else: sock, addr = pair self.remote_clients.append(AirPlayProtocolHandler(sock, self)) def handle_close(self): self.close() def __del__(self): self.thread.end() self.close() del self.thread # unpublish avahi service self.zeroconf_service.unpublish()
def __init__(self, name=None, host="0.0.0.0", port=22555): # create socket server asyncore.dispatcher.__init__(self) self.create_socket(socket.AF_INET, socket.SOCK_STREAM) self.set_reuse_addr() self.bind((host, port)) self.listen(5) self.remote_clients = [] macstr = "%012X" % uuid.getnode() self.deviceid = ''.join("%s:" % macstr[i:i+2] for i in range(0, len(macstr), 2))[:-1] self.features = 0x07 # 0x77 on iOS 4.3.1 self.model = "AppleTV2,1" # create avahi service if (name is None): name = "Airplay Service on " + platform.node() self.zeroconf_service = ZeroconfService(name, port=port, stype="_airplay._tcp", text=["deviceid="+self.deviceid,"features="+hex(self.features),"model="+self.model]) # publish avahi service self.zeroconf_service.publish() # do this so we do not block the main thread self.thread = AsyncoreThread(timeout=30) self.thread.is_finished = False self.thread.start()
#!/usr/bin/env python # -*- coding: utf-8 -*- import time from ZeroconfService import ZeroconfService service = ZeroconfService(name="Shumen's avahi web server", port=80, stype="_http._tcp") service.publish() #most of the time you don't have to run avahi-browse, because your browser can probably find these things for itself. Safari can on the Mac, for example - look for the "Bonjour" menu. #ssh mymachine.local
#!/usr/bin/env python # -*- coding: utf-8 -*- import time from ZeroconfService import ZeroconfService service = ZeroconfService(name="Shumen's avahi web server", port=80, stype="_http._tcp") service.publish() #most of the time you don't have to run avahi-browse, because your browser can probably find these things for itself. Safari can on the Mac, for example - look for the "Bonjour" menu. #ssh mymachine.local