Skip to content

Instantly share code, notes, and snippets.

@jeffbrl
Created November 22, 2014 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffbrl/109d1bf446c5eb7a58aa to your computer and use it in GitHub Desktop.
Save jeffbrl/109d1bf446c5eb7a58aa to your computer and use it in GitHub Desktop.
Obtain KVM guest IPv4 or IPv6 from MAC adddress
#!/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