Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify the multicast SEND interface in Python?

There is quite a few examples to RECEIVE multicast messages with a spcific network interface (NIC, e.g. eth0, 127.0.0.1 etc). However, there is few discussion/examples about how to SEND multicast (UDP) messages to a specific interface, e.g. local loop (127.0.0.1) instead of eth0 by default.

Background: RedHat Linux, Python, 224.1.1.1 5005

Python Code example in Multicast in Python

A similar discuss for IPv6 How to send multicast packets via a specfic interface in Linux

A similar discuss for Windows How to Multicast (send) to first NIC?

Thanks in advance.

like image 941
user1268888 Avatar asked Mar 14 '12 12:03

user1268888


1 Answers

The question that you've linked How to Multicast (send) to first NIC? mentions that you could use IP_MULTICAST_IF:

sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_IF, socket.inet_aton(addr))
like image 95
jfs Avatar answered Oct 14 '22 09:10

jfs