From f7e2fb8cb28a016cfe2beeb534d44652af220e82 Mon Sep 17 00:00:00 2001 From: rhamilton Date: Fri, 15 Aug 2025 19:09:38 +0000 Subject: [PATCH] Update webserver-ip.sh --- webserver-ip.sh | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/webserver-ip.sh b/webserver-ip.sh index 69cbf07..1263d63 100644 --- a/webserver-ip.sh +++ b/webserver-ip.sh @@ -1,11 +1,23 @@ -cat < index.html +#!/usr/bin/env bash +set -euo pipefail + +# Make a minimal HTML page +IP="$(hostname -I | awk '{print $1}')" +cat > index.html < Hello World

Hello from $(hostname)

-

IP address: $(hostname -I | awk '{print $1}')

+

IP address: $IP

EOF -sudo python3 -m http.server 80 +# Serve forever on port 80 with netcat +echo "Serving on http://$IP (Ctrl+C to stop)" +while true; do + { + echo -e "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"; + cat index.html; + } | nc -l -p 80 -q 1 +done