Page 1 of 1

get the networkInterfaces: distinguish more IP

Posted: Wed Jan 11, 2023 2:02 pm
by trevix
Hello.
I use the property "networkInterfaces" in order to obtain the IP number of the device where I am running my stack.

If my device is ethernet wired and it is set so has to run an hotspot (to share with wifi the internet connection), the networinterface as it should, returns 2 IP numbers, beside the 127.xxx.

Is there a way to distinguish in LC which IP is the ethernet IP and which is the hotspot IP?

Thanks for the help
Trevix

Re: get the networkInterfaces: distinguish more IP

Posted: Wed Jan 11, 2023 6:30 pm
by mwieder
On which platform?
You might try shelling out to ifconfig to see which address is attached to the wlan interface.
Unless you're using Windows in which case it's ipconfig.

Re: get the networkInterfaces: distinguish more IP

Posted: Wed Jan 11, 2023 8:39 pm
by trevix
Sorry, on Android.
Server and client are both on a local network.
I have a TvBox that act as a server, connected with ethernet and also sharing internet with the hotspot enabled.
The client (mobile) is always on wifi, and must be given the Ip of the server hotspot, in order to connect
For what I understand, the order of the list returned by "the networinterface" is:
- ethernet IP
- hotspot IP
- local 127.0.0.1

But is this a rule?
Can I count on it?
Or is a router decision?

Re: get the networkInterfaces: distinguish more IP

Posted: Wed Jan 11, 2023 10:14 pm
by mwieder
The client and the server are both on Android?
The order of the interfaces isn't determined by the LiveCode engine - it just returns the result of querying the operating system.

But I'm confused now. I'm probably misunderstanding this, but it sounds like the client connects to the server and then you want the server to send the client a different ip address to connect with instead?

Re: get the networkInterfaces: distinguish more IP

Posted: Thu Jan 12, 2023 11:48 am
by trevix
I am very sorry: this network stuff is very confusing to me and not easy to explain.

The client can be Android or iOS, according to the user cell phone.
The server hardware, which we sell, is always Android and, upon first launch, must be configured with one this two user's choice:
- manually paired to WiFi (if exists) on the OS settings
- connected to ethernet and enabling its hotspot on the OS settings

When the LC app of the server is first launched, it shows a screen with its local IP number, so that the client, after pairing its phone to the same wifi or to the hotspot wifi, can socket connect to it.
What I am trying to solve is to display on the server, when in hotspot mode, the hotspot IP (not the ethernet IP).
The order of the interfaces isn't determined by the LiveCode engine - it just returns the result of querying the operating system.
As a confirmation of your answer, I connected, as a test proof, the mac to wifi and, only after, connected the ethernet cable.
Networinterfaces was returned in this order:
- 127.0.0.1
- IP of wifi
- IP of ethernet
So, apparently, it returns a list according to whatever comes first.

Then I disconnected WiFi, leaving ethernet:
- 127.0.0.1
- ethernet IP ---correct
and enabling again WiFi:
- 127.0.0.1
- IP of wifi
- IP of ethernet

This last order shows that "whatever comes first" is not true.
Any idea?

Re: get the networkInterfaces: distinguish more IP

Posted: Thu Jan 12, 2023 2:53 pm
by trevix
Another reason why I need to distinguish the ethernet IP from the hotspot IP, is that at each hardware restart of the server, the hotspot IP changes.

A different type of user, will connect to the registered server using the QRcode displayed by it.
Since the only way in LC server to see if the user has changed the wifi, in case in the server it is using the wifi, not the hotspot, and that he has to re-enter the SSDI and password to be shown on the QRcode for this type of users, is to check if the IP has changed.

Re: get the networkInterfaces: distinguish more IP

Posted: Thu Jan 12, 2023 7:08 pm
by jacque
Can you assign a static ethernet IP to the server? Then the wifi IP will be the other one. Or maybe you can assign static IPs to both ethernet and wifi?

Re: get the networkInterfaces: distinguish more IP

Posted: Thu Jan 12, 2023 8:40 pm
by mwieder
Also, I'll assume the wifi address is static, or at least the subnet doesn't change. If that's the case, can you just eliminate it from the list?