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

  • Replies:0
Hanbae Seo
  • Forum posts: 2

Mar 21, 2013, 1:29:29 AM via Website

I am looking for ways to find a local IP address of the interface that is a counterpart to default gateway using Android API

-Environment-

1. VPN connection(OpenVPN)
-Default gateway is changed into VPN server IP
-Virtual interface(tunXX) for VPN connection is a counterpart to a default gateway

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 other words, 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

mSocket = new Socket(dstAddress, peerPortNum);
mStrMyIPAddr = mSocket.getLocalAddress().getHostAddress();

But, I don not want to use Socket

Reply