Files
bootstrap-scripts/webserver-ip.sh
2025-08-15 19:09:38 +00:00

24 lines
493 B
Bash

#!/usr/bin/env bash
set -euo pipefail
# Make a minimal HTML page
IP="$(hostname -I | awk '{print $1}')"
cat > index.html <<EOF
<html>
<head><title>Hello World</title></head>
<body>
<h1>Hello from $(hostname)</h1>
<p>IP address: $IP</p>
</body>
</html>
EOF
# 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