pybonjour

pybonjour provides a pure Python interface (via ctypes) to Apple Bonjour and compatible DNS-SD libraries (such as Avahi).
Download

pybonjour Ranking & Summary

Advertisement

  • Rating:
  • License:
  • MIT/X Consortium Lic...
  • Price:
  • FREE
  • Publisher Name:
  • Chris Stawarz
  • Publisher web site:
  • http://o2s.csail.mit.edu/o2s-wiki/multitask

pybonjour Tags


pybonjour Description

pybonjour provides a pure Python interface (via ctypes) to Apple Bonjour and compatible DNS-SD libraries (such as Avahi). pybonjour provides a pure Python interface (via ctypes) to Apple Bonjour and compatible DNS-SD libraries (such as Avahi).The application allows Python scripts to take advantage of Zero Configuration Networking (Zeroconf) to register, discover, and resolve services on both local and wide-area networks.Since pybonjour is implemented in pure Python, scripts that use it can easily be ported to Mac OS X, Windows, Linux, and other systems that run Bonjour.ExamplesThe following scripts are included in the examples directory of the pybonjour source distribution. Registering a Serviceregister.py Scriptimport selectimport sysimport pybonjourname = sys.argvregtype = sys.argvport = int(sys.argv)def register_callback(sdRef, flags, errorCode, name, regtype, domain): if errorCode == pybonjour.kDNSServiceErr_NoError: print 'Registered service:' print ' name =', name print ' regtype =', regtype print ' domain =', domainsdRef = pybonjour.DNSServiceRegister(name = name, regtype = regtype, port = port, callBack = register_callback)try: try: while True: ready = select.select(, [], []) if sdRef in ready: pybonjour.DNSServiceProcessResult(sdRef) except KeyboardInterrupt: passfinally: sdRef.close()Example Output$ python register.py TestService _test._tcp 1234Registered service: name = TestService regtype = _test._tcp. domain = local.Browsing for and Resolving Servicesbrowse_and_resolve.py Scriptimport selectimport sysimport pybonjourregtype = sys.argvtimeout = 5resolved = []def resolve_callback(sdRef, flags, interfaceIndex, errorCode, fullname, hosttarget, port, txtRecord): if errorCode == pybonjour.kDNSServiceErr_NoError: print 'Resolved service:' print ' fullname =', fullname print ' hosttarget =', hosttarget print ' port =', port resolved.append(True)def browse_callback(sdRef, flags, interfaceIndex, errorCode, serviceName, regtype, replyDomain): if errorCode != pybonjour.kDNSServiceErr_NoError: return if not (flags & pybonjour.kDNSServiceFlagsAdd): print 'Service removed' return print 'Service added; resolving' resolve_sdRef = pybonjour.DNSServiceResolve(0, interfaceIndex, serviceName, regtype, replyDomain, resolve_callback) try: while not resolved: ready = select.select(, [], [], timeout) if resolve_sdRef not in ready: print 'Resolve timed out' break pybonjour.DNSServiceProcessResult(resolve_sdRef) else: resolved.pop() finally: resolve_sdRef.close()browse_sdRef = pybonjour.DNSServiceBrowse(regtype = regtype, callBack = browse_callback)try: try: while True: ready = select.select(, [], []) if browse_sdRef in ready: pybonjour.DNSServiceProcessResult(browse_sdRef) except KeyboardInterrupt: passfinally: browse_sdRef.close()Example Output$ python browse_and_resolve.py _test._tcpService added; resolvingResolved service: fullname = TestService._test._tcp.local. hosttarget = bumble.local. port = 1234... Requirements: · Python >= 2.4 · ctypes (version 1.0.1 or later)


pybonjour Related Software