Created
September 3, 2012 08:44
-
-
Save petrblaho/3607944 to your computer and use it in GitHub Desktop.
Simple script for detecting IP address of running virtual machine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
DOMAIN=$1 | |
XML=`sudo virsh dumpxml $DOMAIN` | |
MAC=`echo "$XML" | grep 'mac address' | awk -F\' '{print $2}'` | |
VIRNETWORK=`echo "$XML" | grep 'source network' | awk -F\' '{print $2}'` | |
VIRBRIDGE=`sudo virsh net-info $VIRNETWORK | grep Bridge | awk '{print $2}'` | |
VIRNET=`ifconfig $VIRBRIDGE | grep inet | awk '{print $2}' | awk -F. '{print $1"."$2"."$3".*"}'` | |
nmap -sn $VIRNET &> /dev/null | |
IP=`ip neigh | grep $MAC | awk '{print $1}'` | |
echo $IP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment