Retrieve IP from VM

This commit is contained in:
Kroese 2023-05-08 21:00:37 +02:00 committed by GitHub
parent 0cd215f962
commit afcf200b1b

View File

@ -14,36 +14,37 @@ if [ "$2" != "ipinfo" ]; then
RESPONSE="HTTP/1.1 200 OK\nContent-Length: ${LENGTH}\nConnection: close\n\n$HTML\n\n" RESPONSE="HTTP/1.1 200 OK\nContent-Length: ${LENGTH}\nConnection: close\n\n$HTML\n\n"
while true; do while true; do
echo -en "$RESPONSE" | nc -lp "${1:-5000}" & wait $! echo -en "$RESPONSE" | nc -lp "${1:-5000}" >/dev/null 2>&1 & wait $!
done done
exit 0 exit 0
fi fi
SH_SCRIPT="/run/ipinfo.sh" SH_SCRIPT="/tmp/ipinfo.sh"
{ echo "INFO=\$(curl -s -m 5 -S http://127.0.0.1:2210/read?command=10 2>&1)" { echo "#!/bin/bash"
echo "INFO=\$(curl -s -m 5 -S http://127.0.0.1:2210/read?command=10 2>/dev/null)"
echo "rest=\${INFO#*http_port}" echo "rest=\${INFO#*http_port}"
echo "rest=\${rest#*:}" echo "rest=\${rest#*:}"
echo "rest=\${rest%%,*}" echo "rest=\${rest%%,*}"
echo 'PORT=\${rest%%\"*}' echo "PORT=\${rest%%\\\"*}"
echo "rest=\${INFO#*eth0}" echo "rest=\${INFO#*eth0}"
echo "rest=\${rest#*ip}" echo "rest=\${rest#*ip}"
echo "rest=\${rest#*:}" echo "rest=\${rest#*:}"
echo 'rest=\${rest#*\"}' echo "rest=\${rest#*\\\"}"
echo 'IP=\${rest%%\"*}' echo "IP=\${rest%%\\\"*}"
echo "BODY=\"The location of DSM is http://\${IP}:\${PORT}<script>\ " echo "BODY=\"The location of DSM is <a href=\"http://\${IP}:\${PORT}\">http://\${IP}:\${PORT}</a><script>\\"
echo "setTimeout(function(){ window.location.replace('http://\${IP}:\${PORT}'); }, 2000);</script>\"" echo "setTimeout(function(){ window.location.assign('http://\${IP}:\${PORT}'); }, 3000);</script>\""
echo "HTML=\"<!DOCTYPE html><HTML><HEAD><TITLE>VirtualDSM</TITLE><STYLE>body { color: white; background-color: #125bdb; font-family: Verdana,\ " echo "HTML=\"<!DOCTYPE html><HTML><HEAD><TITLE>VirtualDSM</TITLE><STYLE>body { color: white; background-color: #125bdb; font-family: Verdana,\\"
echo "Arial,sans-serif; } a, a:hover, a:active, a:visited { color: white; }</STYLE></HEAD><BODY><BR><BR><H1><CENTER>\$BODY</CENTER></H1></BODY></HTML>\"" echo "Arial,sans-serif; } a, a:hover, a:active, a:visited { color: white; }</STYLE></HEAD><BODY><BR><BR><H1><CENTER>\$BODY</CENTER></H1></BODY></HTML>\""
echo 'LENGTH="\${#HTML}"' echo "LENGTH=\"\${#HTML}\""
echo 'RESPONSE="HTTP/1.1 200 OK\nContent-Length: \${LENGTH}\nConnection: close\n\n\$HTML\n\n"' echo "RESPONSE=\"HTTP/1.1 200 OK\\nContent-Length: \${LENGTH}\\nConnection: close\\n\\n\$HTML\\n\\n\""
echo 'echo \$RESPONSE' echo "echo -e \"\$RESPONSE\""
} > "$SH_SCRIPT" } > "$SH_SCRIPT"
chmod +x "$SH_SCRIPT" chmod +x "$SH_SCRIPT"
while true ; do while true ; do
nc -lp "${1:-5000}" -e "$SH_SCRIPT" & wait $! nc -lp "${1:-5000}" -e "$SH_SCRIPT" >/dev/null 2>&1 & wait $!
done done