get the networkInterfaces: distinguish more IP

Bringing the internet highway into your project? Building FTP, HTTP, email, chat or other client solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
trevix
Posts: 822
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

get the networkInterfaces: distinguish more IP

Post by trevix » Wed Jan 11, 2023 2:02 pm

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
Trevix
OSX 12.5.1 xCode 13.2 LC 9.6.8 iOs 15> Android 7>

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3468
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: get the networkInterfaces: distinguish more IP

Post by mwieder » Wed Jan 11, 2023 6:30 pm

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.

trevix
Posts: 822
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: get the networkInterfaces: distinguish more IP

Post by trevix » Wed Jan 11, 2023 8:39 pm

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?
Trevix
OSX 12.5.1 xCode 13.2 LC 9.6.8 iOs 15> Android 7>

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3468
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: get the networkInterfaces: distinguish more IP

Post by mwieder » Wed Jan 11, 2023 10:14 pm

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?

trevix
Posts: 822
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: get the networkInterfaces: distinguish more IP

Post by trevix » Thu Jan 12, 2023 11:48 am

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?
Trevix
OSX 12.5.1 xCode 13.2 LC 9.6.8 iOs 15> Android 7>

trevix
Posts: 822
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: get the networkInterfaces: distinguish more IP

Post by trevix » Thu Jan 12, 2023 2:53 pm

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.
Trevix
OSX 12.5.1 xCode 13.2 LC 9.6.8 iOs 15> Android 7>

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6858
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: get the networkInterfaces: distinguish more IP

Post by jacque » Thu Jan 12, 2023 7:08 pm

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?
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3468
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: get the networkInterfaces: distinguish more IP

Post by mwieder » Thu Jan 12, 2023 8:40 pm

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?

Post Reply

Return to “Internet”