-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathServer.py
More file actions
33 lines (26 loc) · 783 Bytes
/
Server.py
File metadata and controls
33 lines (26 loc) · 783 Bytes
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
import subprocess
class Server:
""" A network testing server that can start an iperf3
server on any given port."""
def __init__(self, host, addr):
self.host = host
self.addr = addr
self.ports = []
def listen(self, port):
self.ports.append(port)
def start(self, interval=''):
command = ['ssh', '-n', self.host, 'iperf3', '-s', '-D']
if interval:
command.append('-i' + str(interval))
command.append('-p')
for port in self.ports:
command.append(str(port))
subprocess.Popen(command)
# print ' '.join(map(str, command))
start = command.index(port)
while len(command) > start:
command.pop(start)
def stop(self):
command = ["ssh", "-n", self.host, "pkill", "iperf3"]
subprocess.Popen(command)
# print ' '.join(map(str, command))