title: Shell script to find the IP address of an Virtual machine created by using KVM/virsh command
body: <p>I am looking for the shell script to find the IP address of a virtual machine created by using KVM/VIRSH.</p>
  
  <p>I used the following steps to get it so, but couldn´t able to find it.</p>
  
  <ol>
  <li>Ping the IP addresses in range</li>
  </ol>
  
  <p>2.Use Virsh list command to list all the active VM</p>
  
  <p>3.use Virsh dumpxml domainname and project the xml of vm</p>
  
  <ol start="4">
  <li>use grep command and fetch the Hardware address of vm</li>
  </ol>
  
  <p>5.Display the hardware address of each vm</p>
  
  <p>Now I would like to add one more step like fetching the IP address for that particular Hardware address using ¨arp -ne¨</p>
  
  <p>I couldn´t able to figure out how to add the part.</p>
  
  <p>could any one help me on this.</p>
  
  <pre><code>for i in {1..150}
  do
    ping -c 1 -n -q -r  -t 1 -s 1  -W 1   192.168.1.$i &gt; /dev/null &amp;
  done
  
  
   for name in `virsh list | grep running | awk '{ print $2 }'`
     do
     # printf  "\n$name\n "
      arp -e | grep "`virsh dumpxml  $name | grep "mac address"|sed    "s/.*'\(.*\)'.*/\1/g"`" |
    awk '{ printf  $1 ;  printf  " "  ; printf  $3 "\n" }'
  done
  </code></pre>
  
  <p>current output:</p>
  
  <pre><code>$ ./virshshell.sh
    vm2 52:54:00:4b:7f:41
    vm3 52:54:00:0e:4c:42
  </code></pre>
  
  <p>The output I am expecting is </p>
  
  <pre><code> $ ./virshshell.sh
       vm2 52:54:00:4b:7f:41  192.*.*.*
       vm3 52:54:00:0e:4c:42  192.*.*.*
  </code></pre>