Discover workstations via zeroconf.

portnov [2009-02-23 20:08:26]
Discover workstations via zeroconf.
Filename
discovery.py
test.py
diff --git a/discovery.py b/discovery.py
index 4f9b95f..004b0ec 100644
--- a/discovery.py
+++ b/discovery.py
@@ -11,6 +11,7 @@ def err(str):
 servicenames = {'_ssh._tcp':  'ssh',
                 '_http._tcp': 'web',
                 '_ftp._tcp':  'ftp',
+                '_workstation._tcp': 'machine',
                 '_pulse-server._tcp':  'pulseaudio',
                 '_nameserver._udp': 'dns'}

diff --git a/test.py b/test.py
index 7dd3656..84d690c 100755
--- a/test.py
+++ b/test.py
@@ -49,22 +49,33 @@ class Host(object):
 class ZeroconfListener(object):
     def new_service(self, iface,proto,name,stype,domain, host, aproto,addr, port, txt,flags):
         global services
+        global hosts
+
+        if stype == '_workstation._tcp':
+            host = Host()
+            host.hostname = name.split()[0]
+            host.ip = addr
+            hosts[host.hostname] = host
+            return
+
         sname = discovery.servicenames[stype]
         svc = Service()
         svc.name = name
         svc.ip = addr
         svc.port = port
         services[sname] = svc
-        print "services[%s] = %s" % (sname, svc)
+#         print "services[%s] = %s" % (sname, svc)

 #####################################
 # Setup

 listener = ZeroconfListener()
-browser = discovery.Browser(args=('_ssh._tcp','_pulse-server._tcp','_nameserver._udp'))
+browser = discovery.Browser(args=('_ssh._tcp','_workstation._tcp','_nameserver._udp'))
 browser.set_listener(listener)
 browser.start()

+hosts = {}
+
 services = {}
 services['proxy'] = Service()
 services['proxy'].ip = '192.168.32.3'
@@ -80,6 +91,9 @@ templates.services = services
 templates.machine = machine
 time.sleep(5)

+# print services
+print hosts
+
 # Read template
 system = configs.read_template('configs/templates/system.xml')
ViewGit