throughput_client.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/python3
  2. #
  3. import throughput_protocols
  4. import useful
  5. import os
  6. import argparse
  7. import logging
  8. #
  9. if __name__ == '__main__':
  10. logging.basicConfig(level=logging.DEBUG)
  11. #
  12. parser = argparse.ArgumentParser(description='Test the network throughput (optionally through a proxy).')
  13. parser.add_argument('ip', type=str, help='destination ip address')
  14. parser.add_argument('port', type=int, help='destination port')
  15. parser.add_argument('num_bytes', type=useful.parse_bytes,
  16. help='number of bytes to send (can also end with \'B\', \'KiB\', \'MiB\', or \'GiB\')', metavar='num-bytes')
  17. parser.add_argument('--proxy', type=str, help='proxy ip address and port', metavar=('ip','port'), nargs=2)
  18. parser.add_argument('--wait', type=int,
  19. help='wait until the given time before pushing data (time in seconds since epoch)', metavar='time')
  20. parser.add_argument('--buffer-len', type=useful.parse_bytes,
  21. help='size of the send and receive buffers (can also end with \'B\', \'KiB\', \'MiB\', or \'GiB\')', metavar='bytes')
  22. parser.add_argument('--no-accel', action='store_true', help='don\'t use C acceleration (use pure Python)')
  23. args = parser.parse_args()
  24. #
  25. endpoint = (args.ip, args.port)
  26. proxy = None
  27. #
  28. if args.proxy is not None:
  29. proxy = (args.proxy[0], int(args.proxy[1]))
  30. #
  31. username = bytes([x for x in os.urandom(12) if x != 0])
  32. #username = None
  33. #
  34. client = throughput_protocols.ClientProtocol(endpoint, args.num_bytes, proxy=proxy,
  35. username=username, wait_until=args.wait,
  36. send_buffer_len=args.buffer_len,
  37. use_acceleration=(not args.no_accel))
  38. client.run()
  39. #