Skip to content

Instantly share code, notes, and snippets.

@jkapusi
Last active September 20, 2017 18:00
Show Gist options
  • Save jkapusi/bef4f56387c15d085ad8d529ff6b4538 to your computer and use it in GitHub Desktop.
Save jkapusi/bef4f56387c15d085ad8d529ff6b4538 to your computer and use it in GitHub Desktop.
quick and dirty solution to bind vnc to localhost on a qemu host
#!/bin/bash
apt-get install jq -y
ps axu | grep -oe "unix:[a-z0-9\.:\/\-]*.qmp" | while read QMP; do
echo $QMP;
LISTEN=$(echo -e '{"execute":"qmp_capabilities"}\n{"execute": "query-vnc"}' | socat - ${QMP} | tail -n1 | jq -r .return.host);
echo $LISTEN
if [ "$LISTEN" != "127.0.0.1" ]; then
PORT=$[$(echo -e '{"execute":"qmp_capabilities"}\n{"execute": "query-vnc"}' | socat - ${QMP} | tail -n1 | jq -r .return.service)-5900]
echo -e '{"execute":"qmp_capabilities"}\n{"execute": "change", "arguments": { "device": "vnc", "target": "127.0.0.1:'$PORT'" } }' | socat - ${QMP};
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment