Last active
February 2, 2018 03:44
-
-
Save dan82840/3f24620dc94f439eda6c33c3978de7e1 to your computer and use it in GitHub Desktop.
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 | |
# | |
# ping-via-gateway.sh [Destination IP Address] [Default Gateway IP Address] [Output Interface Name] | |
# | |
SRC_IP= | |
DST_IP=$1 | |
DEFAULT_GW=$2 | |
OUT_INF=$3 | |
PING_CNT=2 | |
PING_TIMEOUT=5 | |
usage() { | |
echo "ping-via-gateway.sh [Destination IP Address] [Default Gateway IP Address] [Output Interface Name]" | |
} | |
if [ $# -ne 3 ]; then | |
usage | |
exit 1 | |
fi | |
SRC_IP=$(ifconfig $OUT_INF | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}') | |
ip route add $DST_IP via $DEFAULT_GW src $SRC_IP dev $OUT_INF | |
ping -I $OUT_INF -c $PING_CNT -W $PING_TIMEOUT $DST_IP | |
ret=$? | |
ip route del $DST_IP via $DEFAULT_GW src $SRC_IP dev $OUT_INF | |
exit $ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment