Last active
August 29, 2015 14:15
-
-
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.
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/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