Reputation: 21
When I connect an Android device to a Windows PC through USB tethering, it creates a network adapter, a Remote NDIS. This adapter's ip address, gateway etc values are set by Android phone(I think). Is there a way to get these values in Android code or app. The ip address here is dynamic(want keep it that way only, do not want to use STATIC ip), with this ip I want to send http request via usb cable to the pc or server.
Upvotes: 2
Views: 4710
Reputation: 21
If you want to find out the IP address of your phone in this connection you can use the following methods:
1) Install applications like "IP Tools" or "Ping Tools", which can display the current state of your network interfaces (check interface "rndis0").
2) Connect the device to the computer and turn on the development mode (which will enable the ADB interface). Then use the adb command-line tool from your PC to access your device: adb shell ip addr
. The following command will display the information about all your network interfaces. You need to check the network interface "rndis0".
3) If you are the application developer you can use the class NetworkInterface (follow the link https://developer.android.com/reference/java/net/NetworkInterface.html).
4) Alternatively connect to the device via SSH (previously install the SSH server application) and use the commands like ip addr
to find out the information about your network interfaces.
Hope, this answer will help someone. :)
Upvotes: 1