Sometimes you have to check if some host replies on ARP “who-has” requests instead of simply pinging it. You probably need it when the host has its firewall configured to deny ICMP “echo” request (as you have probably noticed, most of hosts running Microsoft Windows Server are configured to ignore these requests) to check if the host is up. So, arping really helps, but to use it you have to look up the network interface on which you shall call for this host.
This simple script does it for you: it looks up for the corresponding network interface and calls the arping utility.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#!/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}" ${@} |
Just run it with any parameters you’d like to pass to arping, it will add the “-I” parameter and execute arping.
If I ever update this script, you can get the fresh version from GitHub: https://gist.github.com/melnik13/fb2a05d4084a6c039ccb.
P.S. I’d also suggest you to use arping by Thomas Habets – it doesn’t require you to indicate the interface, as it determines it by itself.
Arping should be looking up the interface automatically.
There is another, inferior, arping implementation that may not look up the interface, but mine does. At least assuming the machine is on that IP subnet.
Thank you for clarification! As I see now, CentOS, RedHat and some other Linux-based operating systems have another utility that doesn’t have too much common with yours. Alas, it’s being installed by default, so for most of users arping requires the -I argument.
I’ll edit the post a bit later to vindicate the truth 🙂