Skip to content

Instantly share code, notes, and snippets.

@DamnedFacts
Last active September 11, 2019 04:42
Show Gist options
  • Select an option

  • Save DamnedFacts/41c26e3e639d0333bfec68ceeeeb14b1 to your computer and use it in GitHub Desktop.

Select an option

Save DamnedFacts/41c26e3e639d0333bfec68ceeeeb14b1 to your computer and use it in GitHub Desktop.
A concocted bandwidth test using Python
#!/usr/bin/python
from http.server import BaseHTTPRequestHandler, HTTPServer
from io import BytesIO
server = None
PORT_NUMBER = 8080
SERVER_IP = "0.0.0.0"
#This class will handles any incoming request from
#the browser
class myHandler(BaseHTTPRequestHandler):
#Handler for the GET requests
def do_GET(self):
self.send_response(200)
self.send_header('Content-type','text/html')
self.end_headers()
# Send the html message
f = b"0"*1024*10
try:
while True:
self.wfile.write(f)
except (BrokenPipeError, ConnectionResetError) as e:
print(e)
try:
#Create a web server and define the handler to manage the
#incoming request
server = HTTPServer((SERVER_IP, PORT_NUMBER), myHandler)
print(f'Started httpserver on port {SERVER_IP}:{PORT_NUMBER}')
#Wait forever for incoming htto requests
server.serve_forever()
except KeyboardInterrupt:
print('^C received, shutting down the web server')
server.socket.close()
# Testing Client
# wget -O /dev/null --recursive=off http://<hostname>/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment