-
Notifications
You must be signed in to change notification settings - Fork 2
/
shrew.py
46 lines (39 loc) · 977 Bytes
/
shrew.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/python
import socket
import sys
from time import time, sleep
""" Used http://www.binarytides.com/programming-udp-sockets-in-python/ """
def shrew():
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
except socket.error:
print 'Failed to create socket'
sys.exit()
start_time = time()
addr = sys.argv[1]
burst_period = float(sys.argv[2])
burst_duration = float(sys.argv[3])
total_time = float(sys.argv[4])
msg = 'a' * 1500
while True:
# burst period
start_burst_time = time()
while True:
s.sendto(msg, (addr, 80))
burst_now = time()
burst_delta = burst_now - start_burst_time
if burst_delta >= burst_duration:
break
now = time()
total_delta = now - start_time
if total_delta > total_time:
break
# silent period
start_silent_time = time()
while True:
sleep_now = time()
sleep_delta = sleep_now - start_silent_time
if sleep_delta >= burst_period:
break
if __name__ == "__main__":
shrew()