From d9a9cdf0822f213038ba89c0ebab630b491ffea4 Mon Sep 17 00:00:00 2001 From: Alexandre Dulaunoy Date: Wed, 5 Dec 2012 18:46:48 +0100 Subject: [PATCH] -s option added for nb_send Sequence is now saved on the sender side in a shelve. --- nb_send.py | 25 ++++++++++++++++++++++++- nb_verify.py | 3 ++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/nb_send.py b/nb_send.py index 64e1432..d925e2c 100644 --- a/nb_send.py +++ b/nb_send.py @@ -1,6 +1,8 @@ import socket import datetime import time +from optparse import OptionParser + try: from hashlib import sha1 except ImportError: @@ -36,5 +38,26 @@ def nbsend(destination=None,payload=None, logging=False): sock.sendto(payload, (destination, 12345)) return True -for x in range(1,10): +usage = "usage: %prog [options] " +parser = OptionParser(usage) +parser.add_option("-s","--storeseq", dest="storeseq", action='store_true', help="store sequence and validate sequence") + +(options, args) = parser.parse_args() + +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'] +else: + seqstart = 1 + +for x in range(seqstart,seqstart+10): nbsend(destination="127.0.0.1", payload=nbmessage(x), logging=True) + if options.storeseq: + s['seq'] = x +if options.storeseq: + s.close() diff --git a/nb_verify.py b/nb_verify.py index d17afee..0880508 100644 --- a/nb_verify.py +++ b/nb_verify.py @@ -43,7 +43,7 @@ def validateseq(seq=None, update=True): return False if not 'seq' in s: s['seq'] = seq - return True + return s['seq'] elif seq == (s['seq']+1): s['seq'] = s['seq'] + 1 return s['seq'] @@ -83,4 +83,5 @@ for line in sys.stdin: print "(!) invalid signature for "+message if options.storeseq: + s['seq'] = s['seq']-1 s.close()