Python: Multicast
Send/Receive multicast messages:
The following code block shows how to instantiate a multicast socket on windows/linux.
Features:
- socket can both send/receive multicast messages
- avoid binding to all interfaces (‘0.0.0.0’), this can be a security issue
Many online examples for python multicast sockets no longer work for newer version of Linux.
This code snippet was tested to work on Ubuntu 22 as of 7/24/2022.
YOU LIE: This code does not work on my system!
There are many linux settings that can prevent application level sockets from capturing multicast messages.
These are the debugging steps I used to diagnose missing multicast messages.
Tools:
- Wireshark (windows/linux)
- tcpdump (linux)
Because Wireshark and tcpdump use “promiscuous mode” it circumvents the usual settings blocking multicast traffic into an application.
example tcpdump call: “tcpdump -i eth0 -s0 -vv host 239.255.255.250”
System Settings:
- Temporarily Turn off firewall (Windows / Linux)
- sudo systemctl stop firewalld (Linux)
- sudo ufw disable (other Linux distros)
- windows defender firewall (Windows)
- Edit /stc/sysctl.conf (Linux)
- rf_filter = 0
There are many stack overflow topics on missing multicast traffic in python but still visable with tcpdump.
I will eventually compile them all into this page but because I am currently lazy, you will have to google yourself.
An example stack overflow page that goes over some first level problems:
https://serverfault.com/questions/163244/linux-kernel-not-passing-through-multicast-udp-packets
working on python 3.8.0-3.8.12 (problems on windows for 3.8.12+ OS_ERROR)
|
|