Skip to content

Instantly share code, notes, and snippets.

@namgk
Forked from talwai/servefile.sh
Last active May 5, 2019 01:14
Show Gist options
  • Save namgk/8598016cab480d65e9e8e4ffd960721b to your computer and use it in GitHub Desktop.
Save namgk/8598016cab480d65e9e8e4ffd960721b to your computer and use it in GitHub Desktop.
One-shot HTTP webserver to serve file contents using netcat
#!/bin/bash
if [[ $# -eq 0 ]]; then
echo "Usage: ./servefile.sh <file to serve>"
echo "Ctrl+C to exit"
exit 1
fi
FILE=$1
while true; do
{ echo -ne "HTTP/1.0 200 OK\r\nContent-Length: $(wc -c < $FILE)\r\n\r\n"; cat $FILE; } | nc -l 4477;
test $? -gt 128 && break;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment