nickovs / slimDNS

Simple, Lightweight Implementation of Multicast DNS
Apache License 2.0
86 stars 9 forks source link

Works on cPython too ? #1

Closed sander76 closed 6 years ago

sander76 commented 6 years ago

If I understand correctly this code allows for getting the ip address of devices which are registered on mDNS with a certain name ?

If so I wonder whether this library can be adapted to work on "normal" python too (and more specifically on windows..) ? I did give it a go myself, but I failed.. I know there are libraries out there doing this already, but they are hard to install or are non-windows.

nickovs commented 6 years ago

Hi @sander76. Yes, this code allows others to find your IP address using mDNS. It absolutely can be made to work on cPython (and that's how I did most of my initial testing). The changes that are needed mostly are in the _make_socket() function where you need to set a bunch of other socket options. Adding this code into this version would increase the code size, so I'd rather not do it here but you are welcome to try.

That said, there are other projects for pure Python mDNS implementations which do not have small size as a primary goal. You should take a look at the standard Python ZeroConf library. This supports everything that my code does and a great deal more, at the expense of a much, much larger memory footprint, the need for threads and some rather less efficient packet handling. You can advertise your IP address (and other services) using the register_service() method of a Zeroconf object. The release notes indicate that it should work on Windows.

I hope that this helps.

sander76 commented 6 years ago

@nickovs Thanks for the detailled response. The thing with ZeroConf library is that it requires NetIfaces. This is a library that cannot be just pip installed on windows: You need to compile it yourself or use a precompiled binary from https://www.lfd.uci.edu/~gohlke/pythonlibs/

As I am targeting windows users that is not a procedure I prefer. I'll have a go with your suggestions... If you can share any more tips they are more than welcome !!

nevercast commented 5 years ago

Just linking this here for anyone that may want to try get slimDNS to work on their dev machine: https://gist.github.com/aaroncohen/4630685

I failed to get slimDNS running in Python 3.6 in Windows, and I couldn't afford the development time to investigate it further. I too suspect there is a missing socket option or the like that is required.

nickovs commented 5 years ago

If there is interest then I could certainly look at creating a version that is designed to work on other platforms. There seem to be three areas necessary to make this happen:

  1. Fixing my dumb bugs like #4 which only manifest themselves when run on versions of python who's libraries perform more input checks than micropython does.
  2. Ensuring that the micropython-specific library functions like those in #5 are properly stubbed out.
  3. Probably the most complex: sorting out all of the various socket options that are needed to enable multicasting in different, platform-specific ways.

For the last item I can test on macOS and Linux but I'd need someone else to test the Windows version.

If people want to run slimDNS on full-size Python then click the smiley on this comment. If I get enough smiles I'll do it!