mcastsock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
mcastsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
mcastsock.setsockopt(socket.SOL_IP, socket.IP_ADD_MEMBERSHIP, socket.
    inet_aton(mcast_addr) + socket.inet_aton(if_ip))
Choosing multicast network interface in Python