-
Notifications
You must be signed in to change notification settings - Fork 0
/
speed_client.py
133 lines (109 loc) · 3.28 KB
/
speed_client.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#! /usr/bin/env python
import sys
import curses
import threading
from random import shuffle
from time import sleep
import __builtin__
from scapy.all import *
scapy_builtins = __import__("scapy.all",globals(),locals(),".").__dict__
__builtin__.__dict__.update(scapy_builtins)
class Transmitter(threading.Thread):
def __init__(self, target):
threading.Thread.__init__(self)
self.target = target
self.payload_sizes = [[i] for i in range(1,2000)]
shuffle(self.payload_sizes)
self.payload_sizes = self.payload_sizes[:500]
def run(self):
global trx_running
global trx_total
for size in self.payload_sizes:
if not trx_running:
trx_total = 0
break
send(IP(dst=self.target)/UDP(dport=12312)/("b"*size[0])*80, verbose=0)
sleep(4) # empty caches
trx_total += size[0]*80
trx_total = 0
trx_running = False
class PBar_Updater(threading.Thread):
def __init__(self, pbar):
threading.Thread.__init__(self)
self.pbar = pbar
def run(self):
global trx_running
while True:
if not trx_running:
show_bar(self.pbar)
self.pbar.addstr(2, 1, "FINISHED, press any key".center(self.pbar.getmaxyx()[1]-2))
self.pbar.refresh()
break
show_pbar(self.pbar)
sleep(1)
def show_bar(bar):
bar.clear()
bar.box()
bar.refresh()
def show_menu(mbar):
show_bar(mbar)
mbar.addstr(0, 2, " PRESS KEY ")
if trx_running:
mbar.addstr(2, 3, "Q", curses.A_UNDERLINE)
mbar.addstr(2, 5, "quit transmission")
else:
mbar.addstr(2, 3, "H", curses.A_UNDERLINE)
mbar.addstr(2, 5, "highspeed recipient")
mbar.addstr(2, 27, "L", curses.A_UNDERLINE)
mbar.addstr(2, 29, "lowspeed recipient")
mbar.addstr(2, 50, "S", curses.A_UNDERLINE)
mbar.addstr(2, 52, "start test")
mbar.addstr(2, 65, "X", curses.A_UNDERLINE)
mbar.addstr(2, 67, "exit")
mbar.refresh()
def show_pbar(pbar):
show_bar(pbar)
if trx_running:
pbar.addstr(2, 1, (str(trx_total/400200) + "%" + " (" + str(trx_total/1024) + "kB)").center(pbar.getmaxyx()[1]-2))
else:
if hs_recipient:
pbar.addstr(2, 1, hs_message.center(pbar.getmaxyx()[1]-2))
else:
pbar.addstr(2, 1, ls_message.center(pbar.getmaxyx()[1]-2))
pbar.refresh()
def curses_gui(cscreen):
global trx_running
global hs_recipient
mbar = curses.newwin(5, cscreen.getmaxyx()[1]-2, 1, 1)
pbar = curses.newwin(5, cscreen.getmaxyx()[1]-2, 6, 1)
while True:
cscreen.clear()
cscreen.refresh()
show_menu(mbar)
show_pbar(pbar)
c = cscreen.getch()
if c == ord('x'):
trx_running = False
break
elif (c == ord('h')) and (not trx_running):
hs_recipient = True
elif (c == ord('l')) and (not trx_running):
hs_recipient = False
elif c == ord('s') and (not trx_running):
trx_running = True
pst = PBar_Updater(pbar)
pst.start()
trx = Transmitter(hs_server if hs_recipient else ls_server)
trx.start()
elif c == ord('q'):
trx_running = False
### Main ###
trx_running = False
trx_total = 0
hs_recipient = True
hs_message = "TARGET: measuring against highspeed datacenter server"
ls_message = "TARGET: measuring against dsl landine server"
hs_server = "terminal21.de"
ls_server = "terminal21.dyndns.org"
curses.wrapper(curses_gui)
curses.endwin()