Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   How write a IGMP V3 request (http://www.velocityreviews.com/forums/t952888-how-write-a-igmp-v3-request.html)

pedr0 10-01-2012 08:14 AM

How write a IGMP V3 request
 
Hello,

I wrote this piece of code but I am not able to modify it in order to use IGMPV3
and use the source feature of IGMPV3, how can I add a membership for a group on an interface for specified source ?

Something like this piece of code (C under Linux):

setsockopt(fd,SOL_IP,MCAST_JOIN_SOURCE_GROUP, &group_source_req,
sizeof(group_source_req));



import socket
import fcntl
import struct
import sys

def get_ip_address(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(
s.fileno(),
0x8915, # SIOCGIFADDR
struct.pack('256s', ifname[:15])
)[20:24])

if len(sys.argv) < 3:
print 'Usage : [MCAST_ADDR] [PORT] [IFNAME]'
sys.exit(1)

MCAST_GRP = sys.argv[1]
MCAST_PORT = int(sys.argv[2])
IF = sys.argv[3]

ip_if = get_ip_address(IF)
packet = 0
print("Capturing from "+IF+"("+ip_if+") group "+MCAST_GRP+":"+str(MCAST_PORT))
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind(('', MCAST_PORT))
sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, socket.inet_aton(MCAST_GRP)+socket.inet_aton(ip_if ))

while True:
try:
sock.recv(1024)
print '1K received'
packet = packet +1
except:
print 'Received '+str(packet*1024)+' bytes'
sock.setsockopt(socket.IPPROTO_IP, socket.IP_DROP_MEMBERSHIP, socket.inet_aton(MCAST_GRP)+socket.inet_aton(ip_if ))
sys.exit(0)



All times are GMT. The time now is 11:03 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.