I have my KVM guests on br0 interface so I think its a bit different, but here is my two scripts I made.
Note to use ARP you first need to have the MAC in your Arp Table. Therefor its best to use fping to do a quick ping of entire network (takes like 2 seconds). This makes sure your Arp cache is up to date.
apt-get install fping yum install fping
Find a single guest IP via :
cat << 'EOF' > ~/findip.sh #!/bin/bash #FreeSoftwareServers.com echo "Finding All Active IP's in Network via single Ping" sleep 2s fping -a -g 192.168.1.0/24 >/dev/null 2>&1 & #nmap -sn 192.168.1.0/24 >/dev/null 2>&1 & echo "Please Enter the Exact Name of the VM Guest:" read guestname arp -na | awk -v mac=$(virsh domiflist $guestname | awk '$2=="bridge"{print $NF}') '$0 ~ " at " mac {gsub("[()]", "", $2); print $2}' EOF chmod +x ~/findip.sh sudo sh -c 'echo "alias findguestip=~/findip.sh" >> ~/.bashrc' source ~/.bashrc findguestip
Find All Guest IP's via:
cat << 'EOF' > ~/findallips.sh #!/bin/bash #FreeSoftwareServers.com echo "Finding All Active IP's in Network via single Ping" sleep 2s fping -a -g 192.168.1.0/24 >/dev/null 2>&1 & #nmap -sn 192.168.1.0/24 >/dev/null 2>&1 & domainlog=/tmp/domain.log virsh list --all | grep running | cut -c 8- >> "$domainlog" sed -i 's/running*//g' "$domainlog" readarray domain < "$domainlog" for i in "${domain[@]}" do ip="$(arp -na | awk -v mac=$(virsh domiflist $i | awk '$2=="bridge"{print $NF}') '$0 ~ " at " mac {gsub("[()]", "", $2); print $2}')" echo "Hostname : $i IP : $ip" done rm "$domainlog" EOF chmod +x ~/findallips.sh sudo sh -c 'echo "alias findallips=~/findallips.sh" >> ~/.bashrc' source ~/.bashrc findallips