Skip to content

Instantly share code, notes, and snippets.

@imesh

imesh/http-server.sh

Created Aug 20, 2017
Embed
What would you like to do?
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