throughput_client.py 1.2 KB

123456789101112131415161718192021222324252627282930313233
  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. args = parser.parse_args()
  21. #
  22. endpoint = (args.ip, args.port)
  23. proxy = None
  24. #
  25. if args.proxy is not None:
  26. proxy = (args.proxy[0], int(args.proxy[1]))
  27. #
  28. username = bytes([x for x in os.urandom(12) if x != 0])
  29. #username = None
  30. #
  31. client = throughput_protocols.ClientProtocol(endpoint, args.num_bytes, proxy=proxy, username=username, wait_until=args.wait)
  32. client.run()
  33. #