I wanted to run iperf with python instead of a shell script, but I didn't have a Japanese document, so I'll leave a simple way to do it.
Ubuntu 14.04 python 3.5.1
First, install the python wrapper using pip.
pip install iperf3
It is also possible to install directly from the github repository without using pip.
git clone https://github.com/thiezn/iperf3-python.git
cd iperf3-python
python3 setup.py install
Server side code
iperf_server.py
#!/usr/bin/env python3
import iperf3
server = iperf3.Server()
print('Running server: {0}:{1}'.format(server.bind_address, server.port))
while True:
result = server.run()
if result.error:
print(result.error)
else:
print('')
print('Test results from {0}:{1}'.format(result.remote_host,
result.remote_port))
print(' started at {0}'.format(result.time))
print(' bytes received {0}'.format(result.received_bytes))
print('Average transmitted received in all sorts of networky formats:')
print(' bits per second (bps) {0}'.format(result.received_bps))
print(' Kilobits per second (kbps) {0}'.format(result.received_kbps))
print(' Megabits per second (Mbps) {0}'.format(result.received_Mbps))
print(' KiloBytes per second (kB/s) {0}'.format(result.received_kB_s))
print(' MegaBytes per second (MB/s) {0}'.format(result.received_MB_s))
print('')
Then the client side code
iperf_client.py
#!/usr/bin/env python3
import iperf3
client = iperf3.Client()
client.duration = 10 # Measurement time [sec]
client.server_hostname = '192.168.1.1' # Server's IP address
print('Connecting to {0}:{1}'.format(client.server_hostname, client.port))
result = client.run()
if result.error:
print(result.error)
else:
print('')
print('Test completed:')
print(' started at {0}'.format(result.time))
print(' bytes transmitted {0}'.format(result.sent_bytes))
print(' retransmits {0}'.format(result.retransmits))
print(' avg cpu load {0}%\n'.format(result.local_cpu_total))
print('Average transmitted data in all sorts of networky formats:')
print(' bits per second (bps) {0}'.format(result.sent_bps))
print(' Kilobits per second (kbps) {0}'.format(result.sent_kbps))
print(' Megabits per second (Mbps) {0}'.format(result.sent_Mbps))
print(' KiloBytes per second (kB/s) {0}'.format(result.sent_kB_s))
print(' MegaBytes per second (MB/s) {0}'.format(result.sent_MB_s))
With this, you can measure the throughput of the network for the time being. The server (192.168.1.1) and the client make measurements using iperf3 for 10 seconds. Although not changed in this code, it is possible to specify the port number and UDP / TCP as well as iperf executed on the command line.
https://pypi.python.org/pypi/iperf3 https://github.com/thiezn/iperf3-python
Recommended Posts