10 server = dbus.Interface(bus.get_object("org.freedesktop.Avahi", '/'), 'org.freedesktop.Avahi.Server')
12 def server_state_changed_callback(t):
13 print "Server::StateChanged: ", t
15 server.connect_to_signal("StateChanged", server_state_changed_callback)
17 print "Version String: ", server.GetVersionString()
19 print server.ResolveHostName(0, 0, "ecstasy.local", 0)
20 print server.ResolveAddress(0, 0, "192.168.50.4")
22 print "Host name: %s" % server.GetHostName()
23 print "Domain name: %s" % server.GetDomainName()
24 print "FQDN: %s" % server.GetHostNameFqdn()
25 print "State: %i" % server.GetState()
27 n = server.GetNetworkInterfaceNameByIndex(2)
28 print "network: 2 -> %s -> %i" % (n, server.GetNetworkInterfaceIndexByName(n))
30 print server.GetAlternativeHostName("gurkiman10")
31 print server.GetAlternativeServiceName("Ahuga Service")
33 def entry_group_state_changed_callback(t):
34 print "EntryGroup::StateChanged: ", t
37 print server.ResolveHostName(0, 0, "foo.local", 0)
39 g = dbus.Interface(bus.get_object("org.freedesktop.Avahi", server.EntryGroupNew()), 'org.freedesktop.Avahi.EntryGroup')
40 g.connect_to_signal('StateChanged', entry_group_state_changed_callback)
41 g.AddService(0, 0, "Test Web Site", "_http._tcp", "", "", dbus.UInt16(4712), ["fuck=hallo", "gurke=mega"])
42 g.AddAddress(0, 0, "foo.local", "47.11.8.15")
45 def domain_browser_callback(a, interface, protocol, domain):
46 print "DOMAIN_BROWSER: %s %i %i %s" % (a, interface, protocol, domain)
48 db = dbus.Interface(bus.get_object("org.freedesktop.Avahi", server.DomainBrowserNew(0, 0, "", 2)), 'org.freedesktop.Avahi.DomainBrowser')
49 db.connect_to_signal('ItemNew', lambda interface, protocol, domain: domain_browser_callback("NEW", interface, protocol, domain))
50 db.connect_to_signal('ItemRemove', lambda interface, protocol, domain: domain_browser_callback("REMOVE", interface, protocol, domain))
52 def service_type_browser_callback(a, interface, protocol, type, domain):
53 print "SERVICE_TYPE_BROWSER: %s %i %i %s %s" % (a, interface, protocol, type, domain)
55 stb = dbus.Interface(bus.get_object("org.freedesktop.Avahi", server.ServiceTypeBrowserNew(0, 0, "")), 'org.freedesktop.Avahi.ServiceTypeBrowser')
56 stb.connect_to_signal('ItemNew', lambda interface, protocol, type, domain: service_type_browser_callback("NEW", interface, protocol, type, domain))
57 stb.connect_to_signal('ItemRemove', lambda interface, protocol, type, domain: service_type_browser_callback("REMOVE", interface, protocol, type, domain))
59 def service_browser_callback(a, interface, protocol, name, type, domain):
60 print "SERVICE_BROWSER: %s %i %i %s %s %s" % (a, interface, protocol, name, type, domain)
63 print server.ResolveService(interface, protocol, name, type, domain, 0)
65 sb = dbus.Interface(bus.get_object("org.freedesktop.Avahi", server.ServiceBrowserNew(0, 0, "_http._tcp", "")), 'org.freedesktop.Avahi.ServiceBrowser')
66 sb.connect_to_signal('ItemNew', lambda interface, protocol, name, type, domain: service_browser_callback("NEW", interface, protocol, name, type, domain))
67 sb.connect_to_signal('ItemRemove', lambda interface, protocol, name, type, domain: service_browser_callback("REMOVE", interface, protocol, name, type, domain))
70 gobject.MainLoop().run()
71 except KeyboardInterrupt, k: