1

Is there a way to "fix" or set up a static ip address of the hotspot? I need to guarantee a peripheral can connect to my server socket on that ip always.

I am trying to connect a wifi peripheral device to a server socket running on my android device. I have the peripheral connected to my android's hotspot with the ssid and ssid password.

Right now as a work around I am using ip 192.168.43.1. Sources here and here say that 192.168.43.1 will is the default. However, I am under the impression that it's possible this ip address could change.

I am also wondering about doing this for iOS but one step at a time.

Many thanks in advance!

luckyging3r
  • 3,047
  • 3
  • 18
  • 37
  • 2
    No. That ip address us always the same. – greenapps Apr 06 '18 at 16:50
  • That is awesome if that is the case! Do you know of any documentation to back that up? – luckyging3r Apr 06 '18 at 16:52
  • I know this is kind of a two part question but what about for iOS? – luckyging3r Apr 06 '18 at 16:54
  • But the formulation of your problem is strange. You would first have to connect your device with the Android device. For that you do not have to know ip. After that an app on yor device should connect wih the serversocket on your Android device. For that you need an ip indeed. But before trying to connect the client could check its own ip address. If it is like 129.168.43.# you know youre in. – greenapps Apr 06 '18 at 16:54
  • Yeah.. It is definitely a strange problem. Basically the app we have asks for the local wifi ssid & pwd then sends that to the peripheral to connect itself to the local wifi. The peripheral is always looking for the ssid on the android and thus allowing us to connect to it if we set the ssid & pwd for the hotspot to the one the peripheral is looking for. – luckyging3r Apr 06 '18 at 16:59

1 Answers1

1

This IP Address is hardcoded for Android as you can see in the source.

if (ifcg != null) {
    /* IP/netmask: 192.168.43.1/255.255.255.0 */
    ifcg.setLinkAddress(new LinkAddress(
        NetworkUtils.numericToInetAddress("192.168.43.1"), 24));
    ifcg.setInterfaceUp();
    mNwService.setInterfaceConfig(intf, ifcg);
}

However a better implementation is for your peripheral device to get the default gateway of the local network as that will work regardless of hotspot implementation.

Dave S
  • 3,378
  • 1
  • 20
  • 34
  • I'm sorry, do you mind if I ask you to elaborate a little bit? I am still kinda new to network programming. How will getting the default gateway help me in this case? By "local network" do you mean my device's hotspot network or my actual local network? – luckyging3r Apr 06 '18 at 19:22
  • The WiFi network (hotspot) provider will always be the default gateway, and by local network I mean the Hotspot network. – Dave S Apr 06 '18 at 19:36
  • So on my android phone I would need to handle or route the incoming peripheral traffic to `192.168.43.1` when they access my default gateway? Is that how that works or am I on another planet? – luckyging3r Apr 06 '18 at 19:50
  • 1
    If your android phone is the hotspot, the default gateway will always be 192.168.43.1. If for some reason Android or iOS change how they handle hotspots and set the device IP to be 192.168.1.1, then the default gateway will be 192.168.1.1. You won't be relying on a hardcoded value. – Dave S Apr 06 '18 at 19:53
  • 1
    It seems like this has now changed to a dynamic address on Android 9. I am using a Vivo 1906 mobile and it seems like the IP of the hotspot is now coming as 192.168.43.x where x changes all the time at each toggle. Maybe it's a change in Vivo Android version. A way to set this in android hotspot settings will be welcome. – Emmanuel Mahuni May 04 '20 at 08:08