Update webserver-ip.sh
This commit is contained in:
@@ -1,7 +1,14 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
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}')"
|
IP="$(hostname -I | awk '{print $1}')"
|
||||||
cat > index.html <<EOF
|
cat > index.html <<EOF
|
||||||
<html>
|
<html>
|
||||||
@@ -13,11 +20,12 @@ cat > index.html <<EOF
|
|||||||
</html>
|
</html>
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# Serve forever on port 80 with netcat
|
echo "[INFO] Serving on http://$IP (Ctrl+C to stop)"
|
||||||
echo "Serving on http://$IP (Ctrl+C to stop)"
|
|
||||||
|
# Serve forever using netcat
|
||||||
while true; do
|
while true; do
|
||||||
{
|
{
|
||||||
echo -e "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
|
echo -e "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
|
||||||
cat index.html;
|
cat index.html;
|
||||||
} | nc -l -p 8080 -q 1
|
} | sudo nc -l -p 8080 -q 1
|
||||||
done
|
done
|
||||||
|
Reference in New Issue
Block a user