OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/python |
| 2 import socket, struct, os, signal, sys |
| 3 # -*- coding: utf-8 -*- |
| 4 |
| 5 """ |
| 6 Script used to join machine into multicast groups. |
| 7 |
| 8 @author Amos Kong <akong@redhat.com> |
| 9 """ |
| 10 |
| 11 if __name__ == "__main__": |
| 12 if len(sys.argv) < 4: |
| 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] |
| 17 sys.exit() |
| 18 |
| 19 mgroup_count = int(sys.argv[1]) |
| 20 prefix = sys.argv[2] |
| 21 suffix = int(sys.argv[3]) |
| 22 |
| 23 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) |
| 24 for i in range(mgroup_count): |
| 25 mcast = prefix + "." + str(suffix + i) |
| 26 try: |
| 27 mreq = struct.pack("4sl", socket.inet_aton(mcast), |
| 28 socket.INADDR_ANY) |
| 29 s.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq) |
| 30 except: |
| 31 s.close() |
| 32 print "Could not join multicast: %s" % mcast |
| 33 raise |
| 34 |
| 35 print "join_mcast_pid:%s" % os.getpid() |
| 36 os.kill(os.getpid(), signal.SIGSTOP) |
| 37 s.close() |
OLD | NEW |