python-zeroconf / python-zeroconf

A pure python implementation of multicast DNS service discovery

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

No service found under Windows but working under Ubuntu VM.

basic-settings opened this issue · comments

I am facing some issues in setting up a client/ServiceBrowser that works under both Win and Linux.

I have the following set-up:

  • Win 7 connected to domain
    • Ethernet config uses IPv4 with Subnet Mask 255.255.255.0
  • Ubuntu VM running on the same system in Oracle VirtualBox with Win Ethernet as Bridged Adapter
    enp0s3 Link encap:Ethernet HWaddr 08:00:27:55:62:63 inet addr:10.121.44.95 Bcast:10.121.44.255 Mask:255.255.255.0 inet6 addr: fe80::aa6b:92c:17c4:cfc8/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1837029 errors:0 dropped:0 overruns:0 frame:0 TX packets:110395 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:467243091 (467.2 MB) TX bytes:7871423 (7.8 MB)
  • The broadcasting systems are running on different Debian systems connected to the network domain

If I run the ServiceBrowser from Windows I don't get any return back. I used the example Browser to test the set-up.
`from zeroconf import ServiceBrowser, Zeroconf

class MyListener(object):

def remove_service(self, zeroconf, type, name):
    print("Service %s removed" % (name,))

def add_service(self, zeroconf, type, name):
    info = zeroconf.get_service_info(type, name)
    print("Service %s added, service info: %s" % (name, info))

zeroconf = Zeroconf()
listener = MyListener()
browser = ServiceBrowser(zeroconf, "_tntsrv._tcp.local.", listener)
try:
input("Press enter to exit...\n\n")
finally:
zeroconf.close()`
Running from withing Ubuntu, it returns all the available services (as expected).

I noticed that if I change HOST_ONLY_NETWORK_MASK from 255.255.255.255 to 255.255.255.0 the opposite happens, where it works under Windows but not under Ubuntu.

This seems to ocurr in line 1603
if addr.get('netmask') != HOST_ONLY_NETWORK_MASK

I'm not experienced enough to find a common ground, but is there any posibility so that it'll work under both systems?

For the time being, removing:
if addr.get('netmask') != HOST_ONLY_NETWORK_MASK

from:
return list(set( addr['addr'] for iface in netifaces.interfaces() for addr in netifaces.ifaddresses(iface).get(address_family, []) if addr.get('netmask') != HOST_ONLY_NETWORK_MASK ))
does the trick.

same here. chromecast is found on ubuntu but not on windows.

commenting out the line

if addr.get('netmask') != HOST_ONLY_NETWORK_MASK

makes it work under win7 too.

commented

I got a similar problem with the ServiceBrowser not finding any devices. The cause was one of zeroconf's dependencies: netifaces. Installing the latest version will download version 0.10.5, but with this version it breaks my ServiceBrowser by not finding anything. Downgrading to 0.10.4 and everything works fine.

pip uninstall netifaces
pip install netifaces==0.10.4

ps. tested with zeroconf version 0.17.6 as well as 0.17.5
ps. I got a windows 32 bit environment, but I think the problem may be platform independent.

I can confirm this problem on python 32 under windows 7.
I have not been able to get netifaces 0.10.4 to successfully build under win7, but the change suggested by @sniperlucian does appear to get it to work.

The problem does not occur with 64 bit python under win7, I don't have an explanation for this though.

The problem is occurring for me on Win10 Python 64-bit. I'm using zeroconf 0.10.5. Same as previous posters, the fix that basic-settings suggested works for me. In my Windows setting, I am not able to easily downgrade to zeroconf 0.10.4 due to not having the C++ build tools (and not wanting to install 4 gigs worth of them).

A full solution would be nice. Also, Windows wheel files for 0.10.4 would be nice as well.

I am seconding @gbiddison on this. We either need to remove this check or change setup.py line 59 to read in order to

        'netifaces<=0.10.4',

Or drop the following check from zeroconf.py line 1590

        if addr.get('netmask') != HOST_ONLY_NETWORK_MASK

Alternately we could modify the above check to only take effect on non windows platforms.

import platform

# intervening code to line 1590
        if (platform.system() == 'Windows') or (addr.get('netmask') != HOST_ONLY_NETWORK_MASK)

Either of these will fix the issue with windows compatibility.

My company would really like to use this as part of our build system, but we cannot do it if windows is not supported.

Version 0.19.0 has just been released with the netifaces<=0.10.4 restriction in place, please reopen the issue if it didn't help.

Thanks @jstasiak!

How long does that usually take to propagate up to PyPI?