Skip to content

Instantly share code, notes, and snippets.

@kenyon
Last active June 15, 2019 20:53
Show Gist options
  • Save kenyon/aed6cd45a137133feea6508c23d35cd3 to your computer and use it in GitHub Desktop.
Save kenyon/aed6cd45a137133feea6508c23d35cd3 to your computer and use it in GitHub Desktop.
get IP addresses of a VM which is running qemu-guest-agent
virsh --connect qemu:///system qemu-agent-command VM_NAME '{"execute":"guest-network-get-interfaces"}' | jq --raw-output '.return[] | select(.name != "lo")["ip-addresses"][] | select(."ip-address-type" == "ipv6") | select(."ip-address"|startswith("fe80")|not)."ip-address"'
Or, simpler: virsh --connect qemu:///system domifaddr VM_NAME --source agent | awk '$NF ~ /:/ && !/(fe80)|::1/ {print $NF}' | cut --delimiter / --fields 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment