Created
November 22, 2014 17:37
-
-
Save jeffbrl/109d1bf446c5eb7a58aa to your computer and use it in GitHub Desktop.
Obtain KVM guest IPv4 or IPv6 from MAC adddress
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 | |
# | |
function get_ip { | |
# Obtain the IPv4 or IPv6 address | |
VERSION=$1 | |
# Use arp to find the IP address you're looking for via its MAC address: | |
IP=$(ip -$VERSION neighbor show | grep $MAC_ADDRESS | awk '{ print $1 }' ) | |
echo $IP | |
} | |
export VM_NAME=$1 | |
export MAC_ADDRESS=`virsh dumpxml $VM_NAME | grep "mac address" | sed "s/.*'\(.*\)'.*/\1/g"` | |
if [ "$2" == "v6" ]; then | |
get_ip 6 | |
else | |
get_ip 4 | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment