I am trying to make an app that requires client's IP address. So far I have a code that generates the IP address of a local device but doesn't supply the IP address of the device that is connected to my local (own) device. The code below gives the IP address of the local device. How can I modify this code to obtain the client's IP address.
public String getLocalIpAddress() {
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(android.content.Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int ipAddress = wifiInfo.getIpAddress();
try {
return InetAddress.getByName(String.format("%d.%d.%d.%d",
(ipAddress & 0xff), (ipAddress >> 8 & 0xff),
(ipAddress >> 16 & 0xff), (ipAddress >> 24 & 0xff))).toString();
} catch (UnknownHostException e) {
e.printStackTrace();
}
return null;
}
Thanks.