sockets - How to send igmp join from specific interface with python ? -
i'm trying implement following program in python send join request specific interface (right kernel choosing default).
import socket import struct import time mcast_grp = '239.0.1.1' mcast_port = 2000 sock = socket.socket(socket.af_inet, socket.sock_dgram, socket.ipproto_udp) sock.setsockopt(socket.sol_socket, socket.so_reuseaddr, 1) sock.bind((mcast_grp, mcast_port)) mreq = struct.pack("4sl", socket.inet_aton(mcast_grp), socket.inaddr_any) sock.setsockopt(socket.ipproto_ip, socket.ip_add_membership, mreq)
i trying change socket.inaddr_any
socket.inet_aton('x.x.x.x')
when x.x.x.x
interface ip address represent string, got error.
any way can make work?
thanks, talor
found answer: need change "4sl" "4s4s" , express interface want send igmp join request four-bytes string. can write code follow:
interface = '168.152.63.15' mreq = struct.pack("4s4s", socket.inet_aton(mcast_grp), socket.inet_aton(interface))
Comments
Post a Comment