How to get a local IP of the interface that directly connects to a default gateway

  • Replies:0
Hanbae Seo
  • Forum posts: 2

Mar 21, 2013, 1:32:49 AM via Website

-Environment-

1. VPN connection
- Virtual interface(tun0) for VPN connection directly connects to a default gateway that is changed into VPN server IP
2. Interfaces & default gateway

interfaces :
lo inet addr:127.0.0.1
wlan0 inet addr:150.149.131.5
tun0 inet addr:10.8.0.14

default gateway : 10.8.0.2
In this environment, I want to know "10.8.0.14" regardless of the interface name using Android API.

I cound find only a way to get default route IP address below

1mSocket = new Socket(dstAddress, peerPortNum);
2mStrMyIPAddr = mSocket.getLocalAddress().getHostAddress();
But, I do not want to use Socket

— modified on Mar 21, 2013, 5:38:55 AM

Reply