Skip to content

Instantly share code, notes, and snippets.

@vbuaraujo
Created January 5, 2018 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vbuaraujo/df988e41f853700d2116d98052c5ce18 to your computer and use it in GitHub Desktop.
Save vbuaraujo/df988e41f853700d2116d98052c5ce18 to your computer and use it in GitHub Desktop.
Webserver with netcat
#!/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