Update webserver-ip.sh
This commit is contained in:
@@ -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 <<EOF
|
||||
<html>
|
||||
@@ -13,11 +20,12 @@ cat > index.html <<EOF
|
||||
</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
|
||||
|
Reference in New Issue
Block a user