Created
January 5, 2018 16:55
-
-
Save vbuaraujo/df988e41f853700d2116d98052c5ce18 to your computer and use it in GitHub Desktop.
Webserver with 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 | |
main() { | |
if [[ $INSIDE_NETCAT ]]; then | |
serve_request | |
else | |
export INSIDE_NETCAT=1 | |
while :; do | |
netcat -q 0 -v -l -p 9000 -c "$0" | |
done | |
fi | |
} | |
serve_request() { | |
read request | |
while read header && [[ $header != $'\r' ]]; do | |
: | |
done | |
printf "HTTP/1.0 200 OK\r\n" | |
printf "Content-type: text/plain; charset=UTF-8\r\n" | |
printf "\r\n" | |
echo "Bem-vindos! Bem-vindos ao netcat do seu Shitaki. Ok?" | |
echo "Request = $request" | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment