Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > How write a IGMP V3 request

Reply
Thread Tools

How write a IGMP V3 request

 
 
pedr0
Guest
Posts: n/a
 
      10-01-2012
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)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
CGMP, IGMP Snooping, and the PIX Mike S. Whitlow Cisco 3 12-03-2003 02:53 PM
IGMP configuration Konrad Cisco 2 11-15-2003 07:18 PM
IGMP v1 v2 v3 Snooping Questions Ross Cisco 0 10-23-2003 07:01 PM
Re: Accessing Request.InputStream / Request.BinaryRead *as the request is occuring*: How??? Brian Birtle ASP .Net 2 10-16-2003 02:11 PM



Advertisments