Thanks Justin and Osier. I had searched for a leases file on the machine before, but couldn't find it so thank you for pointing that out. I had thought about installing nmap, but figured I had to have some better record on the machine itself.

Thanks also for the tip on Rich's blog post. I found it at http://rwmj.wordpress.com/2010/10/26/tip-find-the-ip-address-of-a-virtual-machine/

JSR/

On Tue, Jan 18, 2011 at 4:01 AM, Osier Yang <jyang@redhat.com> wrote:
于 2011年01月18日 04:45, Josiah Ritchie 写道:

I'm trying to figure out how to use virsh (or something else) to list
all the IP addresses (or MAC addresses if needed) for each virtual NIC,
preferably with it domain affiliation also listed.

Is this possible?


== method 1: (simple but not reliable)
# cat /var/lib/dnsmasq/dnsmasq.leases
1295343272 52:54:00:6f:2e:72 192.168.122.118 * *

== method 2:
# This script is to map MAC into IP, accepts two
# arguments, subnet prefix and MAC address of the
# interface.
#! /bin/bash

if [ $# -ne 2 ]; then
   echo "Usage: $(basename $0) <SUBNET> <MAC>"
   exit 1
fi

SUBNET=$1
MAC=$2

rpm -q nmap > /dev/NULL
if [ $? -ne 0 ]; then
   echo "You need install nmap"
   exit 1
fi

if [[ -n $SUBNET ]]; then
  OUTPUT=$(nmap -sP -n $SUBNET | grep -i -B 2 $MAC)
  if [[ -n $OUTPUT ]]; then
     IP=$(echo $OUTPUT | sed -e 's/.* \([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\).*/\1/')
  fi
fi

echo $IP

e.g. for a guest which use libvirt "default" network, get the subnet
like:
# ip route | grep "virbr0" | sed -n 1p | awk '{print $1}'

you could write automate script to parse the MAC address of domain
interfaces, the bridge name, and the subnet prefix of bridge, and
then use the script above the get the IP.

And as Justin said, Rich has more clever tool to do it, I also forgot,
you can wait him, :-)

Regards
Osier

JSR/



_______________________________________________
libvirt-users mailing list
libvirt-users@redhat.com
https://www.redhat.com/mailman/listinfo/libvirt-users

_______________________________________________
libvirt-users mailing list
libvirt-users@redhat.com
https://www.redhat.com/mailman/listinfo/libvirt-users