In the VM, on Redhat-likes, make sure that the Qemu guest agent is installed:
dnf install qemu-guest-agent
On Debian-likes, execute:
apt install qemu-guest-agent
For Microsoft Windows guests, there are some tutorials on the web, see for example [1].
On the HV, execute:
virsh qemu-agent-command --domain myvm \
'{"execute":"guest-network-get-interfaces"}' | \
jq -r '
[.return[] | select(.name!="lo") | ."ip-addresses"] | flatten |
.[] | select(."ip-address-type"=="ipv4")."ip-address"
'
The output should be one IPv4 address per line.
If you are interested in IPv4 and IPv6 addresses instead, just skip the „select“ filter:
virsh qemu-agent-command --domain myvm \
'{"execute":"guest-network-get-interfaces"}' | \
jq -r '
[.return[] | select(.name!="lo") | ."ip-addresses"] | flatten |
.[]."ip-address" '