Update webserver-ip.sh

This commit is contained in:
2025-08-15 19:09:38 +00:00
parent 39e093ca07
commit f7e2fb8cb2

View File

@@ -1,11 +1,23 @@
cat <<EOF > index.html
#!/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: $(hostname -I | awk '{print $1}')</p>
<p>IP address: $IP</p>
</body>
</html>
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