Created
August 20, 2013 08:32
-
-
Save ducalpha/6278722 to your computer and use it in GitHub Desktop.
extract IP address, default gateway, and add/del rule to routing table on Android/Linux
This file contains 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
#!/system/bin/sh | |
IF=$1 | |
CMD=$2 | |
SERVER_NET='143.248.140.0/24' | |
IP=`ip -4 addr show $IF | grep 'inet ' | awk '{print $2}' | sed -e 's/\/[0-9]*//'` | |
DEF_GW=`ip ro show | grep -o "default.*$IF" | head -n1 | awk '{print $3}'` | |
if [ $# -ne 2 ] | |
then | |
echo "Usage: `basename $0` <network_name> <add|del>" | |
exit | |
fi | |
echo "IF: $IF" | |
echo "IP: $IP" | |
echo "DEF_GW: $DEF_GW" | |
echo "$CMD rule via $IF" | |
su -c "ip ro $CMD ta main $SERVER_NET via $DEF_GW dev $IF" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment