Force Zeroconf to listen and answer only on interface specified with '-i' command line argument.
authorEdouard Tisserant
Tue, 23 Oct 2018 13:34:15 +0200
changeset 2320 dd959601e67a
parent 2319 0a951f528c69
child 2321 0a3103cd825d
Force Zeroconf to listen and answer only on interface specified with '-i' command line argument.
runtime/ServicePublisher.py
--- a/runtime/ServicePublisher.py	Tue Oct 23 13:31:26 2018 +0200
+++ b/runtime/ServicePublisher.py	Tue Oct 23 13:34:15 2018 +0200
@@ -56,11 +56,15 @@
         self.name = name
         self.port = port
 
-        self.server = zeroconf.Zeroconf()
-        print("MDNS brodcasting on :" + ip)
+        if ip == "0.0.0.0":
+            print("MDNS brodcasted on all interfaces")
+            interfaces=zeroconf.InterfaceChoice.All
+            ip = self.gethostaddr()
+        else:
+            interfaces=[ip]
 
-        if ip == "0.0.0.0":
-            ip = self.gethostaddr()
+        self.server = zeroconf.Zeroconf(interfaces=interfaces)
+        
         print("MDNS brodcasted service address :" + ip)
         self.ip_32b = socket.inet_aton(ip)