查看KVM宿主机上虚拟机的IP的脚本
#!/bin/bash #Auth:liucx #ping当前网段内在线的主机,以便产生arp记录. for ip in 172.16.0.{1..254};do { ping -c1 $subnet$ip >/dev/null 2>&1 }& done sleep 2 #依次查找arp记录. running_vms=`virsh list |grep running` echo -ne "共有`echo "$running_vms"|wc -l`个虚拟机在运行. " 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 " $i $ip done