Skip to content

Instantly share code, notes, and snippets.

@krono
Last active October 19, 2018 12:14
Show Gist options
  • Save krono/538708928afcf16bfee0508fe9b93c95 to your computer and use it in GitHub Desktop.
Save krono/538708928afcf16bfee0508fe9b93c95 to your computer and use it in GitHub Desktop.
Send ip addresses to Xen for info on OpenBSD
for ifline in $(dmesg | grep address | sed -E -e 's/^(xnf.+)\ at.*address\ ([a-fA-F0-9:]+)/\1=\2/' | sort); do
mac=$(echo $ifline | cut -d= -f2)
if=$(echo $ifline | cut -d= -f1)
for vif in $(hostctl device/vif); do
if [ "$mac" = "$(hostctl device/vif/$vif/mac)" ]; then
ip4=$(ifconfig $if | grep 'inet[^6]' | cut -d ' ' -f2)
ip6=$(ifconfig $if | grep 'inet6' | cut -d ' ' -f2 | cut -d% -f1)
if [ -n "$ip4" ]; then
hostctl attr/eth$vif/ip "$ip4"
fi
if [ -n "$ip6" ]; then
hostctl attr/eth$vif/ipv6/0/addr "$ip6"
fi
fi
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment