Is there any method for getting the routing table entry in Android?
Please share the information..
It is possible to get it through the ADB.
You can get the routing table with
$ cat /proc/net/route
You can also execute these commands from within your program. I found this post that discusses this option. There is no answer however. If you could elaborate on what exactly you want in the end I can edit my answer to try and help out more.
Thanks to Paul M for the hint!.
On my Android 6.0.1 (LineageOS)
/system/bin/ip route show table 0
shows routes of all tables
/system/bin/ip route show table rmnet0
shows route table which used when rmnet0 is active interface (mobile data).
/system/bin/ip route show table wlan0
shows route table which used when wlan0 is active.
in “Developers options” it is possible to keep rmnet0 active, even while wlan0 is active. But only one interface will be used at the same time (and one route table).
When WiFi connected to the network, but has no internet link, interface rmnet0 will be selected as main and route table will be used from rmnet0 table.
When WiFi has internet link, wlan0 will be used as main interface and “ip route show table wlan0” as current route table.
you can add or delete route from/to any route table as usual with ip command by adding “table xxx” to route string.
/system/bin/ip route delete table wlan0 default via 192.168.7.1 dev wlan0 proto static /system/bin/ip route add table wlan0 192.168.7.0/24 dev wlan0 proto kernel scope link src 192.168.7.10 metric 327
All route tables will be overwritten every time interface goes on/off, lease renewed, etc…
Using Android Device Bridge(ADB)
Open the command prompt(windows) or terminal(mac & linux)
cd(change directory) to platform-tools directory which is inside android sdk
adb shell cat /proc/net/route
Mac & Linux
./adb shell cat /proc/net/route
adb shell "ip route show"
I found for myself more useful and easier to handle parsing.
Android doesn’t use just one routing table, so viewing the default or main table won’t always help you!
If you run the command “ip rule list” then you will see how many routing tables there are; the “lookup nnnn” is the table. Then you can look at the specific table with “ip route show table 1006” for example.
I’m afraid I can’t tell you which routing table is necessarily the one you want to look at, sorry.