32 lines
685 B
Bash
32 lines
685 B
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# 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 <<EOF
|
|
<html>
|
|
<head><title>Hello World</title></head>
|
|
<body>
|
|
<h1>Hello from $(hostname)</h1>
|
|
<p>IP address: $IP</p>
|
|
</body>
|
|
</html>
|
|
EOF
|
|
|
|
echo "[INFO] Serving on http://$IP:8080 (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;
|
|
} | sudo nc -l -p 8080 -q 1
|
|
done
|