Skip to content

Instantly share code, notes, and snippets.

@khmarochos
Last active August 29, 2015 14:15
Show Gist options
  • Save khmarochos/fb2a05d4084a6c039ccb to your computer and use it in GitHub Desktop.
Save khmarochos/fb2a05d4084a6c039ccb to your computer and use it in GitHub Desktop.
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