I am currently writing a python program that needs to discover other instances of itself on LAN. It uses UDP broadcasts for discovery (255.255.255.255
).
The problem is that if the computer has multiple network adapters (is connected to multiple networks) then only one of those networks will receive the broadcast. My initial idea was to enumerate through all network addresses assigned to local networks and send a broadcast packet for each one (for example 192.168.0.255
and 192.168.1.255
). However, there seems to be no reliable way to detect all the local network addresses as everything I found and tried either relies on python-2-only library or returns only 127.0.1.1
on my linux virtual machine (which has 192.168.0.100
and some others).
How can I broadcast to all available networks in this case?
I'm using Python 3 and am looking for platform-independent way to do it, and without big third-party libraries. A library that correctly
displays all network interfaces would do the job.