Skip to content

Instantly share code, notes, and snippets.

@queencitycyber
Created August 17, 2022 14:20
Show Gist options
  • Save queencitycyber/f49ccce513b8bb1358361a90b56933ea to your computer and use it in GitHub Desktop.
Save queencitycyber/f49ccce513b8bb1358361a90b56933ea to your computer and use it in GitHub Desktop.
Multi-threaded SimpleHTTPServer
#!/usr/bin/python3
import argparse
import http.server
import socketserver
import sys
class ThreadedHTTPServer(socketserver.ThreadingMixIn, http.server.HTTPServer):
pass
def main(argv):
parser = argparse.ArgumentParser()
parser.add_argument(
"--port", type = int, nargs = "?",
action = "store", default = 8000,
help = "Specify alternate port [default: 8000]",
)
parser.add_argument(
"--iface", type = str, nargs = "?",
action = "store", default = "127.0.0.1",
help = "Specify iface [default: 127.0.0.1]",
)
args = parser.parse_args(argv[1:])
server_address = (args.iface, args.port)
srv = ThreadedHTTPServer(server_address, http.server.SimpleHTTPRequestHandler)
sa = srv.socket.getsockname()
print("Serving http://%s:%r ..." % (sa[0], sa[1]))
srv.serve_forever()
if __name__ == "__main__":
sys.exit(main(sys.argv))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment