liucx

 

查看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`个虚拟机在运行.\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

分类:

技术点:

相关文章:

  • 2021-11-28
  • 2021-04-09
  • 2021-11-28
  • 2021-09-15
  • 2021-12-26
  • 2022-01-18
  • 2021-06-15
  • 2021-06-30
猜你喜欢
  • 2021-11-28
  • 2021-11-28
  • 2021-11-28
  • 2022-12-23
  • 2021-05-19
相关资源
相似解决方案