Skip to content

Instantly share code, notes, and snippets.

@francisco-perez-sorrosal
Last active March 2, 2020 21:54
Show Gist options
  • Save francisco-perez-sorrosal/5da1dd83620d61407c27dae25a82b6b6 to your computer and use it in GitHub Desktop.
Save francisco-perez-sorrosal/5da1dd83620d61407c27dae25a82b6b6 to your computer and use it in GitHub Desktop.
Netcat Webserver with config Serving Delay
#!/bin/bash
PORT=${1:-8000}
SERVING_DELAY_SECS=${2:-10}
command -v pv >/dev/null 2>&1 || { echo >&2 "pv requied but not installed. Exiting..."; exit 1; }
cat <<EOF > /tmp/index.html
<!doctype html>
<html>
<body>
<h1>A webpage served by netcat</h1>
</body>
</html>
EOF
echo "Launching netcat Web Server in port $PORT with rate limit of $SERVING_DELAY_SECS secs"
while true; do pv --rate-limit $SERVING_DELAY_SECS /tmp/index.html | nc -l $PORT; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment