Last active
November 23, 2016 19:36
-
-
Save NeoCat/9903497 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
type=ipv4 | |
function usage() { | |
echo "usage: $(basename "$0") [OPTIONS] domain" | |
echo " -6 get ipv6 address (default: ipv4)" | |
echo " -h show this help" | |
echo " -n show interface name" | |
echo " -p show prefix" | |
echo " -i interface specify interface (default: all)" | |
exit | |
} | |
while getopts "6hi:np" flag; do | |
case $flag in | |
6) type=ipv6;; | |
i) filter='select(.name == "'"$OPTARG"'") |';; | |
n) name='.name + ":\t" + ';; | |
p) prefix='+ "/" + (.prefix | tostring)';; | |
h) usage;; | |
esac | |
done | |
shift $((OPTIND-1)) | |
[ -z "$1" ] && usage | |
sudo virsh qemu-agent-command "$1" \ | |
'{"execute":"guest-network-get-interfaces"}' | \ | |
jq -r ' | |
.return [] | '"$filter"' | |
select(."ip-addresses") | | |
{name, addr: (."ip-addresses"[] | select(."ip-address-type"=="'$type'") | | |
."ip-address" '"$prefix"')} | | |
'"$name"'.addr' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment