From e5121985cc6c51411a5b667b9f9d696e6c35e7c7 Mon Sep 17 00:00:00 2001 From: Alexandre Dulaunoy Date: Sat, 8 Jun 2013 10:00:12 +0200 Subject: [PATCH] Multiple destinations option added Multiple destinations via the -d option can be set: python nb_send.py -d 127.0.0.1 -d 127.0.0.2 -s --- nb_send.py | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/nb_send.py b/nb_send.py index 8ceaf57..a4c978b 100644 --- a/nb_send.py +++ b/nb_send.py @@ -43,7 +43,7 @@ parser = OptionParser(usage) parser.add_option("-p","--psk", dest="psk", help="pre-shared key used by the HMAC-SHA1 (default: netbeacon)") parser.add_option("-s","--storeseq", dest="storeseq", action='store_true', help="store sequence and validate sequence") parser.add_option("-i","--iteration", dest="iteration", type=int, help="set the number of interation for sending the netbeacon") -parser.add_option("-d","--destination", dest="destination", help="set the destination IPv4 address (default: 127.0.0.1)") +parser.add_option("-d","--destination", dest="destinations", action="append", help="set the destination(s) IPv4 address (default: 127.0.0.1)") parser.add_option("-v","--verbose", dest="verbose", action='store_true', help="output netbeacon sent") (options, args) = parser.parse_args() @@ -52,27 +52,34 @@ if options.psk: else: psk = "netbeacon" +destinations = [] + +if not options.destinations: + destinations.append("127.0.0.1") +else: + for v in options.destinations: + destinations.append(v) + if options.storeseq: import shelve s = shelve.open("netbeacon-send.seq") - if 'seq' not in s: - s['seq'] = 1 - seqstart = s['seq'] - else: - seqstart = s['seq'] + for destination in destinations: + k = 'seq:' + str(destination) + print (k) + if k not in s: + s[k] = 1 + seqstart = s[k]+1 else: seqstart = 1 if not options.iteration: options.iteration=10 -if not options.destination: - options.destination="127.0.0.1" - -for x in range(seqstart,seqstart+options.iteration): - nbsend(destination=options.destination, payload=nbmessage(x, psk=psk), logging=options.verbose) - if options.storeseq: - s['seq'] = x +for destination in destinations: + for x in range(seqstart,seqstart+options.iteration): + nbsend(destination=destination, payload=nbmessage(x, psk=psk), logging=options.verbose) + if options.storeseq: + s['seq:'+str(destination)] = x if options.storeseq: s.close()