I'm currently using
public static String getLocalIPAddress(WifiManager wm){
return Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress());
}
to get the IP-Address of the executing devices. That works fine if the device is connected to a "common" wlan-network as well as the device is connected to a wifi network which is hosted by an other android device via hotspot. If the device is not connected to any wifi network "0.0.0.0" is returned (correct). But if the device is hosting a wifi network by providing a hotspot the methode is still returning "0.0.0.0". How can I get the real IP-Address of a hotspot providing device "in its own wifi-network"?
thx & regards
You're almost right, the default IP address of hotspot is
192.168.43.1
(If device maker didn't change.)You can check the source code of Android framework (AOSP).
/frameworks/base/services/java/com/android/server/connectivity/Tethering.java
/frameworks/base/wifi/java/android/net/wifi/WifiStateMachine.java
In the Tethering.java,
Also, in the WifiStateMachine.java
Therefore, the default value is
192.168.43.1
.The Hotspot likely acts as a DHCP server. so,
then
will return ip address of connected hotspot, and yes most default IP address of hotspot is 192.168.43.1
I tested a small couple of different devices and it seems that the hotspot providing device has always the IP
192.168.43.1
on its network. Can somebody please check/confirm this assumption?