port = 8080
address = "127.0.0.1"
use_host_names = False
+domain = "local"
class AvahiBookmarks(resource.Resource):
isLeaf = True
def browse_service_type(self, stype):
- browser = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, self.server.ServiceBrowserNew(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, stype, "local")), avahi.DBUS_INTERFACE_SERVICE_BROWSER)
+ global domain
+
+ browser = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, self.server.ServiceBrowserNew(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, stype, domain, 0)), avahi.DBUS_INTERFACE_SERVICE_BROWSER)
browser.connect_to_signal('ItemNew', self.new_service)
browser.connect_to_signal('ItemRemove', self.remove_service)
return t
- def new_service(self, interface, protocol, name, type, domain):
+ def new_service(self, interface, protocol, name, type, domain, flags):
- interface, protocol, name, type, domain, host, aprotocol, address, port, txt = self.server.ResolveService(interface, protocol, name, type, domain, avahi.PROTO_UNSPEC)
+ interface, protocol, name, type, domain, host, aprotocol, address, port, txt, flags = self.server.ResolveService(interface, protocol, name, type, domain, avahi.PROTO_UNSPEC, 0)
if use_host_names:
h = host
print " -p --port PORT Specify the port to use (default %u)" % port
print " -a --address ADDRESS Specify the address to bind to (default %s)" % address
print " -H --host-names Show all services, regardless of the type"
+ print " -d --domain DOMAIN Specify the domain to browse"
sys.exit(retval)
try:
- opts, args = getopt.getopt(sys.argv[1:], "hp:a:H", ["help", "port=", "address=", "host-names"])
+ opts, args = getopt.getopt(sys.argv[1:], "hp:a:Hd:", ["help", "port=", "address=", "host-names", "domain="])
except getopt.GetoptError:
usage(2)
if o in ("-H", "--host-names"):
use_host_names = True
+
+ if o in ("-d", "--domain"):
+ domain = a
site = server.Site(AvahiBookmarks())
reactor.listenTCP(port, site, interface=address)
except KeyError:
return "n/a"
-def service_resolved(interface, protocol, name, stype, domain, host, aprotocol, address, port, txt):
+def service_resolved(interface, protocol, name, stype, domain, host, aprotocol, address, port, txt, flags):
print "Service data for service '%s' of type '%s' (%s) in domain '%s' on %s.%i:" % (name, stype, lookup_service_type(stype), domain, siocgifname(interface), protocol)
print "\tHost %s (%s), port %i, TXT data: %s" % (host, address, port, avahi.txt_array_to_string_array(txt))
def print_error(err):
print "Error:", str(err)
-def new_service(interface, protocol, name, stype, domain):
+def new_service(interface, protocol, name, stype, domain, flags):
global server
print "Found service '%s' of type '%s' (%s) in domain '%s' on %s.%i." % (name, stype, lookup_service_type(stype), domain, siocgifname(interface), protocol)
# Asynchronous resolving
- server.ResolveService(interface, protocol, name, stype, domain, avahi.PROTO_UNSPEC, reply_handler=service_resolved, error_handler=print_error)
+ server.ResolveService(interface, protocol, name, stype, domain, avahi.PROTO_UNSPEC, 0, reply_handler=service_resolved, error_handler=print_error)
-def remove_service(interface, protocol, name, stype, domain):
+def remove_service(interface, protocol, name, stype, domain, flags):
print "Service '%s' of type '%s' (%s) in domain '%s' on %s.%i disappeared." % (name, stype, lookup_service_type(stype), domain, siocgifname(interface), protocol)
-def new_service_type(interface, protocol, stype, domain):
+def new_service_type(interface, protocol, stype, domain, flags):
global server, service_browsers
# Are we already browsing this domain for this type?
print "Browsing for services of type '%s' (%s) in domain '%s' on %s.%i ..." % (stype, lookup_service_type(stype), domain, siocgifname(interface), protocol)
- b = dbus.Interface(bus.get_object(avahi.DBUS_NAME, server.ServiceBrowserNew(interface, protocol, stype, domain)), avahi.DBUS_INTERFACE_SERVICE_BROWSER)
+ b = dbus.Interface(bus.get_object(avahi.DBUS_NAME, server.ServiceBrowserNew(interface, protocol, stype, domain, 0)), avahi.DBUS_INTERFACE_SERVICE_BROWSER)
b.connect_to_signal('ItemNew', new_service)
b.connect_to_signal('ItemRemove', remove_service)
if stype is None:
print "Browsing domain '%s' on %s.%i ..." % (domain, siocgifname(interface), protocol)
- b = dbus.Interface(bus.get_object(avahi.DBUS_NAME, server.ServiceTypeBrowserNew(interface, protocol, domain)), avahi.DBUS_INTERFACE_SERVICE_TYPE_BROWSER)
+ b = dbus.Interface(bus.get_object(avahi.DBUS_NAME, server.ServiceTypeBrowserNew(interface, protocol, domain, 0)), avahi.DBUS_INTERFACE_SERVICE_TYPE_BROWSER)
b.connect_to_signal('ItemNew', new_service_type)
service_type_browsers[(interface, protocol, domain)] = b
else:
- new_service_type(interface, protocol, stype, domain)
+ new_service_type(interface, protocol, stype, domain, 0)
-def new_domain(interface, protocol, domain):
+def new_domain(interface, protocol, domain, flags):
# We browse for .local anyway...
if domain != "local":
browse_domain(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, "local")
# Browse for other browsable domains
- db = dbus.Interface(bus.get_object(avahi.DBUS_NAME, server.DomainBrowserNew(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, "", avahi.DOMAIN_BROWSER_BROWSE)), avahi.DBUS_INTERFACE_DOMAIN_BROWSER)
+ db = dbus.Interface(bus.get_object(avahi.DBUS_NAME, server.DomainBrowserNew(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, "", avahi.DOMAIN_BROWSER_BROWSE, 0)), avahi.DBUS_INTERFACE_DOMAIN_BROWSER)
db.connect_to_signal('ItemNew', new_domain)
else:
self.info_label.set_markup("<i>No service currently selected.</i>")
return
#Asynchronous resolving
- self.server.ResolveService( int(interface), int(protocol), name, stype, domain, avahi.PROTO_UNSPEC, reply_handler=self.service_resolved, error_handler=self.print_error)
+ self.server.ResolveService( int(interface), int(protocol), name, stype, domain, avahi.PROTO_UNSPEC, 0, reply_handler=self.service_resolved, error_handler=self.print_error)
def protoname(self,protocol):
else:
return self.server.GetNetworkInterfaceNameByIndex(interface)
- def service_resolved(self, interface, protocol, name, stype, domain, host, aprotocol, address, port, txt):
+ def service_resolved(self, interface, protocol, name, stype, domain, host, aprotocol, address, port, txt, flags):
print "Service data for service '%s' of type '%s' in domain '%s' on %i.%i:" % (name, stype, domain, interface, protocol)
print "\tHost %s (%s), port %i, TXT data: %s" % (host, address, port, str(avahi.txt_array_to_string_array(txt)))
except KeyError:
return stype
- def new_service(self, interface, protocol, name, stype, domain):
+ def new_service(self, interface, protocol, name, stype, domain, flags):
print "Found service '%s' of type '%s' in domain '%s' on %i.%i." % (name, stype, domain, interface, protocol)
if self.zc_ifaces.has_key((interface,protocol)) == False:
self.zc_ifaces[(interface,protocol)] = self.insert_row(self.treemodel, None, str(self.siocgifname(interface))+" "+str(self.protoname(protocol)),None,interface,protocol,None,domain)
self.tree_view.expand_to_path(self.treemodel.get_path(treeiter))
- def remove_service(self, interface, protocol, name, stype, domain):
+ def remove_service(self, interface, protocol, name, stype, domain, flags):
print "Service '%s' of type '%s' in domain '%s' on %i.%i disappeared." % (name, stype, domain, interface, protocol)
self.info_label.set_markup("")
treeiter=self.services_browsed[(interface, protocol, name, stype, domain)]
del self.zc_ifaces[(interface,protocol)]
- def new_service_type(self, interface, protocol, stype, domain):
+ def new_service_type(self, interface, protocol, stype, domain, flags):
global service_browsers
# Are we already browsing this domain for this type?
print "Browsing for services of type '%s' in domain '%s' on %i.%i ..." % (stype, domain, interface, protocol)
- b = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, self.server.ServiceBrowserNew(interface, protocol, stype, domain)), avahi.DBUS_INTERFACE_SERVICE_BROWSER)
+ b = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, self.server.ServiceBrowserNew(interface, protocol, stype, domain, 0)), avahi.DBUS_INTERFACE_SERVICE_BROWSER)
b.connect_to_signal('ItemNew', self.new_service)
b.connect_to_signal('ItemRemove', self.remove_service)
if self.stype is None:
print "Browsing domain '%s' on %i.%i ..." % (domain, interface, protocol)
- b = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, self.server.ServiceTypeBrowserNew(interface, protocol, domain)), avahi.DBUS_INTERFACE_SERVICE_TYPE_BROWSER)
+ b = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, self.server.ServiceTypeBrowserNew(interface, protocol, domain, 0)), avahi.DBUS_INTERFACE_SERVICE_TYPE_BROWSER)
b.connect_to_signal('ItemNew', self.new_service_type)
service_type_browsers[(interface, protocol, domain)] = b
else:
new_service_type(interface, protocol, stype, domain)
- def new_domain(self,interface, protocol, domain):
+ def new_domain(self,interface, protocol, domain, flags):
if self.zc_ifaces.has_key((interface,protocol)) == False:
self.zc_ifaces[(interface,protocol)] = self.insert_row(self.treemodel, None, str(self.siocgifname(interface))+" "+str(self.protoname(protocol)),None,interface,protocol,None,domain)
if self.zc_domains.has_key((interface,protocol,domain)) == False:
self.browse_domain(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, "local")
# Browse for other browsable domains
- db = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, self.server.DomainBrowserNew(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, "", avahi.DOMAIN_BROWSER_BROWSE)), avahi.DBUS_INTERFACE_DOMAIN_BROWSER)
+ db = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, self.server.DomainBrowserNew(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, "", avahi.DOMAIN_BROWSER_BROWSE, 0)), avahi.DBUS_INTERFACE_DOMAIN_BROWSER)
db.connect_to_signal('ItemNew', self.new_domain)
else:
# Just browse the domain the user wants us to browse
for a in sys.argv[1:]:
try:
- r = server.ResolveAddress(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, a)
+ r = server.ResolveAddress(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, a, 0)
print r[3], r[4]
except dbus.DBusException, e:
print "Resolving '%s' failed: %s" % (a, str(e))
for name in sys.argv[1:]:
try:
- r = server.ResolveHostName(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, name, avahi.PROTO_UNSPEC)
+ r = server.ResolveHostName(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, name, avahi.PROTO_UNSPEC, 0)
print r[2], r[4]
except dbus.DBusException, e:
print "Resolving '%s' failed: %s" % (name, str(e))