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.<div>
<br></div><div>Thanks also for the tip on Rich's blog post. I found it at <a href="http://rwmj.wordpress.com/2010/10/26/tip-find-the-ip-address-of-a-virtual-machine/">http://rwmj.wordpress.com/2010/10/26/tip-find-the-ip-address-of-a-virtual-machine/</a></div>
<div><br></div><div>JSR/<div><br><div class="gmail_quote">On Tue, Jan 18, 2011 at 4:01 AM, Osier Yang <span dir="ltr"><<a href="mailto:jyang@redhat.com">jyang@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
于 2011年01月18日 04:45, Josiah Ritchie 写道:<div><div></div><div class="h5"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I'm trying to figure out how to use virsh (or something else) to list<br>
all the IP addresses (or MAC addresses if needed) for each virtual NIC,<br>
preferably with it domain affiliation also listed.<br>
<br>
Is this possible?<br>
<br>
</blockquote>
<br></div></div>
== method 1: (simple but not reliable)<br>
# cat /var/lib/dnsmasq/dnsmasq.leases<br>
1295343272 52:54:00:6f:2e:72 192.168.122.118 * *<br>
<br>
== method 2:<br>
# This script is to map MAC into IP, accepts two<br>
# arguments, subnet prefix and MAC address of the<br>
# interface.<br>
#! /bin/bash<br>
<br>
if [ $# -ne 2 ]; then<br>
    echo "Usage: $(basename $0) <SUBNET> <MAC>"<br>
    exit 1<br>
fi<br>
<br>
SUBNET=$1<br>
MAC=$2<br>
<br>
rpm -q nmap > /dev/NULL<br>
if [ $? -ne 0 ]; then<br>
    echo "You need install nmap"<br>
    exit 1<br>
fi<br>
<br>
if [[ -n $SUBNET ]]; then<br>
   OUTPUT=$(nmap -sP -n $SUBNET | grep -i -B 2 $MAC)<br>
   if [[ -n $OUTPUT ]]; then<br>
      IP=$(echo $OUTPUT | sed -e 's/.* \([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\).*/\1/')<br>
   fi<br>
fi<br>
<br>
echo $IP<br>
<br>
e.g. for a guest which use libvirt "default" network, get the subnet<br>
like:<br>
# ip route | grep "virbr0" | sed -n 1p | awk '{print $1}'<br>
<br>
you could write automate script to parse the MAC address of domain<br>
interfaces, the bridge name, and the subnet prefix of bridge, and<br>
then use the script above the get the IP.<br>
<br>
And as Justin said, Rich has more clever tool to do it, I also forgot,<br>
you can wait him, :-)<br>
<br>
Regards<br>
Osier<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
JSR/<br>
<br>
<br>
<br>
_______________________________________________<br>
libvirt-users mailing list<br>
<a href="mailto:libvirt-users@redhat.com" target="_blank">libvirt-users@redhat.com</a><br>
<a href="https://www.redhat.com/mailman/listinfo/libvirt-users" target="_blank">https://www.redhat.com/mailman/listinfo/libvirt-users</a><br>
</blockquote>
<br>
_______________________________________________<br>
libvirt-users mailing list<br>
<a href="mailto:libvirt-users@redhat.com" target="_blank">libvirt-users@redhat.com</a><br>
<a href="https://www.redhat.com/mailman/listinfo/libvirt-users" target="_blank">https://www.redhat.com/mailman/listinfo/libvirt-users</a></blockquote></div><br></div></div>