


Putting this together gets us something along the lines of:


# Get the MAC address of the first interface.
mac=$(virsh dumpxml $1 |
  xml2  |
  awk -F= '$1 == "/domain/devices/interface/mac/@address" {print $2; exit}')

# Get the ip address assigned to this MAC from dnsmasq
ip=$(awk -vmac=$mac '$2 == mac {print $3}' /var/lib/libvirt/dnsmasq/default.leases )
echo $ip


This uses xml2 to transform the XML description into something more amendable to processing in a shell script. You could accomplish much the same thing using some sort of XPath based tool. For example:

mac=$(virsh dumpxml $1 |
  xmllint --xpath //interface'[1]/mac/@address' - |
  sed 's/.*="\([^"]*\)"/\1/'

xmllint is part of libxml2.