Skip to content

Instantly share code, notes, and snippets.

@imesh
Created August 20, 2017 10:24
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 imesh/ed6eda3a01aadeebdd17048cb58acbed to your computer and use it in GitHub Desktop.
Save imesh/ed6eda3a01aadeebdd17048cb58acbed to your computer and use it in GitHub Desktop.
Bash HTTP Server
#!/usr/bin/env bash
ip=`ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'`
response="HTTP/1.1 200 OK\r\nConnection: keep-alive\r\n\r\n${2:-"OK ${ip}"}\r\n"
while { echo -en "${response}"; } | nc -l "${1:-8080}"; do
echo ""
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment