Skip to content

Instantly share code, notes, and snippets.

@petrblaho
Created September 3, 2012 08:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save petrblaho/3607944 to your computer and use it in GitHub Desktop.
Save petrblaho/3607944 to your computer and use it in GitHub Desktop.
Simple script for detecting IP address of running virtual machine
#!/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