Skip to content

Instantly share code, notes, and snippets.

@hughpearse
hughpearse / WebServer.py
Last active January 2, 2020 11:53 — forked from joncardasis/WebServer.py
A simple and quick HTTP web server in Python
#!/usr/bin/python
import socket
import signal # Allow socket destruction on Ctrl+C
import sys
import time
import threading
import getopt
class WebServer(object):
"""
@hughpearse
hughpearse / ncws
Created January 21, 2019 14:25 — forked from kevn-xyz/ncws
Simple netcat based one shot http file server
#!/bin/bash
file=$1
port=$2
if [[ -n "$file" ]] && [[ -n "$port" ]]; then
{ echo -ne "HTTP/1.0 200 OK\nContent-Type: application/octet-stream\nContent-Disposition: inline; filename=\"$1\"\nContent-Length: $(wc -c < $file)\n\n"; cat $file; } | nc -l $port
else
echo "Usage: $(basename $0) <file> <port>"
fi