-
-
Save namgk/8598016cab480d65e9e8e4ffd960721b to your computer and use it in GitHub Desktop.
One-shot HTTP webserver to serve file contents using netcat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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