View KVM IP on the host virtual machine script

 

View KVM IP on the host virtual machine script

#!/bin/bash
#Auth:liucx
#ping current online network segment host, in order to generate arp records.
for ip in 172.16.0.{1..254};do
{
ping -c1 $subnet$ip >/dev/null 2>&1
}&
done
sleep 2
# Arp order to find records.
running_vms=`virsh list |grep running`
echo -ne "共有`echo "$running_vms"|wc -l`个虚拟机在运行.\n"
for i in `echo "$running_vms" | awk '{ print $2 }'`;do
mac=`virsh dumpxml $i |grep "mac address"|sed "s/.*'\(.*\)'.*/\1/g"`
ip=`arp -ne |grep "$mac" |awk '{printf $1}'`
printf "%-30s %-30s\n" $i $ip
done

Guess you like

Origin www.cnblogs.com/liucx/p/12170256.html