-s option added for nb_send

Sequence is now saved on the sender side in a shelve.
This commit is contained in:
Alexandre Dulaunoy 2012-12-05 18:46:48 +01:00
parent 6544699165
commit d9a9cdf082
2 changed files with 26 additions and 2 deletions

View file

@ -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] <netbeacon messages>"
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()

View file

@ -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()