From 6d13545a8549582460a578c026cfbb1c650736ac Mon Sep 17 00:00:00 2001 From: rhamilton Date: Fri, 15 Aug 2025 19:17:53 +0000 Subject: [PATCH] Update webserver-ip.sh --- webserver-ip.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/webserver-ip.sh b/webserver-ip.sh index 76bd3cb..29cca43 100644 --- a/webserver-ip.sh +++ b/webserver-ip.sh @@ -1,7 +1,14 @@ #!/usr/bin/env bash set -euo pipefail -# Make a minimal HTML page +# Install netcat if missing +if ! command -v nc >/dev/null 2>&1; then + echo "[INFO] Installing netcat..." + sudo apt update + sudo apt install -y netcat-openbsd +fi + +# Create HTML page with hostname + IP IP="$(hostname -I | awk '{print $1}')" cat > index.html < @@ -13,11 +20,12 @@ cat > index.html < EOF -# Serve forever on port 80 with netcat -echo "Serving on http://$IP (Ctrl+C to stop)" +echo "[INFO] Serving on http://$IP (Ctrl+C to stop)" + +# Serve forever using netcat 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 8080 -q 1 + } | sudo nc -l -p 8080 -q 1 done