My local IP address
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
My local IP address
Hi all,
I use the well known code to get my local IP address: the hostNameToAddress of the hostName
This is working on Mac and PC, but always give 127.0.0.0 on Androïd.
An idea?
Thanks
I use the well known code to get my local IP address: the hostNameToAddress of the hostName
This is working on Mac and PC, but always give 127.0.0.0 on Androïd.
An idea?
Thanks
-
- VIP Livecode Opensource Backer
- Posts: 7257
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: My local IP address
Be sure that the Internet permission is selected in the Android pane in standalone settings. Also check the Inclusions pane to be sure internet is selected there too, and TSNet as well.
Edit: the hostName on my Android device always returns "localhost". I don't know if this is protected information on Android or a bug in LC.
Edit: the hostName on my Android device always returns "localhost". I don't know if this is protected information on Android or a bug in LC.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- VIP Livecode Opensource Backer
- Posts: 9850
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: My local IP address
This comes up a lot, and depending on a wide range of factors can be non-trivial.
Let's explore the use-case to find the best solution: Why does your app need the device's local IP?
Let's explore the use-case to find the best solution: Why does your app need the device's local IP?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: My local IP address
Hi,
In fact, I don't need the local IP address but the IP address of my server (I can easily discover it from the first)..
I have an application which uses sockets to communicate with a server.
Here is a part of my code:
put "192.168.1.4" into ServerIP
put 9001 into bPort
put ServerIP & ":" & bPort into tSocket
open socket to tSocket
write something to socket tSocket with message "dataSent"
read from socket tSocket until theEnd
If my app runs on a PC or a Mac, I can use "hostNameToAddress of the hostName" to receive "192.168.1.4".
But on Androïd, I receive 127.0.0.0... And thus I must hardcode the IP address...
Best
In fact, I don't need the local IP address but the IP address of my server (I can easily discover it from the first)..
I have an application which uses sockets to communicate with a server.
Here is a part of my code:
put "192.168.1.4" into ServerIP
put 9001 into bPort
put ServerIP & ":" & bPort into tSocket
open socket to tSocket
write something to socket tSocket with message "dataSent"
read from socket tSocket until theEnd
If my app runs on a PC or a Mac, I can use "hostNameToAddress of the hostName" to receive "192.168.1.4".
But on Androïd, I receive 127.0.0.0... And thus I must hardcode the IP address...
Best
Re: My local IP address
Hi Jacqueline,
The Internet permission is selected in the Androïd pane.
The inclusions field is empty. How do I fill it?
In the general panel, I see two Radio buttons "Search for required inclusions..." and "Select inclusions..."
The "Search..." is checked.
But the result is the same if I choose "Select".
How can I obtain "Internet" and "TSNet"?
Thanks
The Internet permission is selected in the Androïd pane.
The inclusions field is empty. How do I fill it?
In the general panel, I see two Radio buttons "Search for required inclusions..." and "Select inclusions..."
The "Search..." is checked.
But the result is the same if I choose "Select".
How can I obtain "Internet" and "TSNet"?
Thanks
-
- VIP Livecode Opensource Backer
- Posts: 7257
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: My local IP address
The "Select inclusions" radio button should enable the Extensions tab. In there you can choose all the libraries and widgets the app requires. In general I only use this manual method because searching doesn't always find everything.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- VIP Livecode Opensource Backer
- Posts: 9850
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: My local IP address
DNS is usually cached, so subsequent calls to a domain carry no penalty.
What prevents you from using the domain name?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: My local IP address
Sorry, but it works on my Mac and my PC but not in Androïd.
Mac:
answer the hostname -> iMac-de-Guy-2.lan
answer hostnametoadress(the hostname) -> 192.168.1.4 = my IP
PC:
answer the hostname -> Guy-PC
answer hostnametoadress(the hostname) -> 192.168.1.4 = my IP
Androïd:
answer the hostname -> localhost
answer hostnametoadress(the hostname) -> 127.0.0.0
Re: My local IP address
Android:
Code: Select all
put URL "https://wtfismyip.com/text" into temp
answer ("Your current IP is " & temp)
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
-
- Posts: 722
- Joined: Thu Sep 11, 2014 1:49 pm
- Location: The Netherlands
Re: My local IP address
One can also use tsNetGetSync for many rest API 's.
I used it e.g. for getting currency exchange information and stock information.
Make a button with the code below and make a field named "TheAnswer"
This rest API will get your internet known IP adres.
Read the dictionary for more information.
Have fun,
Paul
I used it e.g. for getting currency exchange information and stock information.
Make a button with the code below and make a field named "TheAnswer"
This rest API will get your internet known IP adres.
Read the dictionary for more information.
Code: Select all
on mouseUp
put "" into fld "TheAnswer"
tsNetInit
tsNetSetTimeouts 5,5000, 5000, 5000, 0, 0
put "https://api.ipify.org?format=json" into tGetString
put tsNetGetSync(tGetString, tHeaders, tRecvHeaders, tResult, tBytes) into tTheAnswer
tsNetClose
put tTheAnswer into fld "TheAnswer"
end mouseUp
Paul
Re: My local IP address
I knew that. But my application runs in an environment where some users have only a simple WIFI router. Thus, no access to Internet.MaxV wrote: ↑Fri Oct 06, 2017 3:37 pmAndroid:Code: Select all
put URL "https://wtfismyip.com/text" into temp answer ("Your current IP is " & temp)
Furthemore, this code gives the external IP address (i.e. 253.128.166.xxx) and not the internal IP address (i.e. 192.168.1.4).
Thanks
Re: My local IP address
Thanks Paul, but I make the same reply as before: some of my users have only a WIFI router and not access to Internet.mrcoollion wrote: ↑Fri Oct 06, 2017 9:41 pmOne can also use tsNetGetSync for many rest API 's.
Have fun,Code: Select all
on mouseUp put "" into fld "TheAnswer" tsNetInit tsNetSetTimeouts 5,5000, 5000, 5000, 0, 0 put "https://api.ipify.org?format=json" into tGetString put tsNetGetSync(tGetString, tHeaders, tRecvHeaders, tResult, tBytes) into tTheAnswer tsNetClose put tTheAnswer into fld "TheAnswer" end mouseUp
Paul
-
- VIP Livecode Opensource Backer
- Posts: 9850
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: My local IP address
I think I didn't pose my question clearly: why use the IP address at all? Why not make the server calls using the domain name?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: My local IP address
I think you don't really understand my problem...FourthWorld wrote: ↑Thu Oct 05, 2017 11:43 pmI think I didn't pose my question clearly: why use the IP address at all? Why not make the server calls using the domain name?
The server is always on a PC or a Mac.
The clients are always on an Androïd tablet.
The communication protocol uses sockets.
Imagine the local address of the server is "192.168.1.4".
Thus, on the clients, I must use the code: "open socket to serverIP address+ port", i.e. open socket "192.168.1.4:9001"
1) If the clients runs on a PC or a Mac, there is no problem.
First I must use hostNameToAddress of the hostName to discover the IP address of the client, it gives me for example "192.168.1.8".
Then, I make a loop of open sockets to "192.168.1.x" for x=1...255 and I will discover the address of the server...
No problem to communicate...
2) Now, if the client runs on Androïd, the problem arises with the same code.
The hostname() gives me "localhost" and hostNameToAddress of the hostName gives me "127.0.0.1".
No open socket loop works to discover "192.168.1.4"... This is my problem!
Since a long time, I use this solution to the problem:
The first time the program runs, it asks the user to give the address of the server. And save it somewhere.
Then all works fine.
The next times, the programs loads this address and all works fine too.
But... It means the PC/Mac user must fix the IP address.
And, if the server address changes, the client must then ask the new IP address.
It would be fine, if I can find a solution which works on Mac/PC and Androïd.
There are theoretically shell solutions, but shell is not available on mobiles.
Is it now clear?
Tanks
-
- Posts: 722
- Joined: Thu Sep 11, 2014 1:49 pm
- Location: The Netherlands
Re: My local IP address
Hi gl,
I now understand what you need (sorry, i am also very bad in reading manuals too ) and have been testing on my android phone.
You Are correct that :
'put the hostname into tThisDeviceHostName' gives 'localhost' which should be the the actual device name of the mobile device
then of-course 'put the hostNameToAddress of tThisDeviceHostName into tHostIPAddress' gives the localhost adres 127.0.0.0 (which is not what we are looking for).
I have tried to resolve a DNS name of one of my servers at home ' put the hostNameToAddress of "MYHOMESERVER_DNSNAME" ' which works fine in windows but gives no answer in android.
In my opinion this is also wrong.
I would suggest you submit a bug report because in my opinion these are very important commands for network usage or they should at least give us another way to get the device IP-Address and hostname and the abillity resolve other hostnames on android (and ios).
let us know the results...
Kind regards,
Paul
I now understand what you need (sorry, i am also very bad in reading manuals too ) and have been testing on my android phone.
You Are correct that :
'put the hostname into tThisDeviceHostName' gives 'localhost' which should be the the actual device name of the mobile device
then of-course 'put the hostNameToAddress of tThisDeviceHostName into tHostIPAddress' gives the localhost adres 127.0.0.0 (which is not what we are looking for).
I have tried to resolve a DNS name of one of my servers at home ' put the hostNameToAddress of "MYHOMESERVER_DNSNAME" ' which works fine in windows but gives no answer in android.
In my opinion this is also wrong.
I would suggest you submit a bug report because in my opinion these are very important commands for network usage or they should at least give us another way to get the device IP-Address and hostname and the abillity resolve other hostnames on android (and ios).
let us know the results...
Kind regards,
Paul
Last edited by mrcoollion on Sun Oct 08, 2017 11:50 am, edited 2 times in total.