2 import socket
, struct
, os
, signal
, sys
3 # -*- coding: utf-8 -*-
6 Script used to join machine into multicast groups.
8 @author Amos Kong <akong@redhat.com>
11 if __name__
== "__main__":
13 print """%s [mgroup_count] [prefix] [suffix]
14 mgroup_count: count of multicast addresses
15 prefix: multicast address prefix
16 suffix: multicast address suffix""" % sys
.argv
[0]
19 mgroup_count
= int(sys
.argv
[1])
21 suffix
= int(sys
.argv
[3])
23 s
= socket
.socket(socket
.AF_INET
, socket
.SOCK_DGRAM
)
24 for i
in range(mgroup_count
):
25 mcast
= prefix
+ "." + str(suffix
+ i
)
27 mreq
= struct
.pack("4sl", socket
.inet_aton(mcast
),
29 s
.setsockopt(socket
.IPPROTO_IP
, socket
.IP_ADD_MEMBERSHIP
, mreq
)
32 print "Could not join multicast: %s" % mcast
35 print "join_mcast_pid:%s" % os
.getpid()
36 os
.kill(os
.getpid(), signal
.SIGSTOP
)