Skip to content

Instantly share code, notes, and snippets.

@melnik13 melnik13/aarping.sh
Last active Aug 29, 2015

Embed
What would you like to do?
Need to check some host's availability by arping, but have no time to look up which network intrface you need? aarping.sh is here to help you.
#!/bin/sh
if [ -z "${1}" ]; then
echo "Chocho?" >&2
exit 1
fi
HOSTIP="${@: -1}"
ROUTE=$(ip route get "${HOSTIP}")
if [ -z "${ROUTE}" ]; then
echo "Can't find the route to this host" >&2
exit 1
fi
IFACE=$(echo "${ROUTE}" | sed -rn "s/^.*dev (eth.[0-9\.]+)[[:space:]]+.*$/\1/gp")
if [ -z "${IFACE}" ]; then
echo "Can't find the interface of this host" >&2
exit 1
fi
exec arping -I "${IFACE}" ${@}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.