mirror of
https://github.com/adulau/netbeacon.git
synced 2024-11-23 18:47:10 +00:00
-s option added for nb_send
Sequence is now saved on the sender side in a shelve.
This commit is contained in:
parent
6544699165
commit
d9a9cdf082
2 changed files with 26 additions and 2 deletions
25
nb_send.py
25
nb_send.py
|
@ -1,6 +1,8 @@
|
||||||
import socket
|
import socket
|
||||||
import datetime
|
import datetime
|
||||||
import time
|
import time
|
||||||
|
from optparse import OptionParser
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from hashlib import sha1
|
from hashlib import sha1
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -36,5 +38,26 @@ def nbsend(destination=None,payload=None, logging=False):
|
||||||
sock.sendto(payload, (destination, 12345))
|
sock.sendto(payload, (destination, 12345))
|
||||||
return True
|
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)
|
nbsend(destination="127.0.0.1", payload=nbmessage(x), logging=True)
|
||||||
|
if options.storeseq:
|
||||||
|
s['seq'] = x
|
||||||
|
if options.storeseq:
|
||||||
|
s.close()
|
||||||
|
|
|
@ -43,7 +43,7 @@ def validateseq(seq=None, update=True):
|
||||||
return False
|
return False
|
||||||
if not 'seq' in s:
|
if not 'seq' in s:
|
||||||
s['seq'] = seq
|
s['seq'] = seq
|
||||||
return True
|
return s['seq']
|
||||||
elif seq == (s['seq']+1):
|
elif seq == (s['seq']+1):
|
||||||
s['seq'] = s['seq'] + 1
|
s['seq'] = s['seq'] + 1
|
||||||
return s['seq']
|
return s['seq']
|
||||||
|
@ -83,4 +83,5 @@ for line in sys.stdin:
|
||||||
print "(!) invalid signature for "+message
|
print "(!) invalid signature for "+message
|
||||||
|
|
||||||
if options.storeseq:
|
if options.storeseq:
|
||||||
|
s['seq'] = s['seq']-1
|
||||||
s.close()
|
s.close()
|
||||||
|
|
Loading…
Reference in a new issue