Page 1 of 2
How do I get the IP address?
Posted: 15 Oct 2013 05:19
by abbood99
hello,
I'm trying to get the IP address and send it as a text message, but I can't find the action which gets you the external and/or internal IP. If anyone has thoughts on this I'll really appreciate your help.
Re: How do I get the IP address?
Posted: 15 Oct 2013 16:09
by Martin
Hi,
There is no built-in action to get the IP address but you can use following actions to get the information:
-action Execute Command: netcfg
or for one interface
-action Execute Command: ifconfig wlan0 resp. Execute Command: ifconfig rmnet0
The action will store the output in a variable called stdout. You have to use a script and functions to extract the part you are interested in.
For example:
-action Execute Command: ifconfig wlan0
This stores the following text in variable stdout:
wlan0: ip 192.168.1.45 mask 255.255.255.0 flags [up broadcast running multicast]
use an action script to split the text on the whitespace characters into words/tokens:
tokens = split(stdout, "\\s");
then use function getElement to store the third word in a variable called ip:
ip = getElement(tokens, 2);
display the variable ip on screen:
-action Notification on Screen: {ip}
You can also combine the scripts directly into the notification but it's much harder to debug when something goes wrong:
-action Notification on Screen: {getElement(split(stdout, "\\s"), 2)}
Regards,
Martin
Re: How do I get the IP address?
Posted: 15 Oct 2013 20:26
by abbood99
Thanks for your elaborate response! I will surely try it.
I'm not sure why the developers would ignore such an essential and intuitive action! Scripting and comand lines can be daunting for people like me. It's almost a deal breaker for people who need this feature.
Best,,,,
Re: How do I get the IP address?
Posted: 03 Aug 2014 16:55
by sambarlick
Thanks for this script Martin!
Exactly what i needed for a flow to display the ip address on the statusbar when connected to a wifi.
Thanks, Sam
Re: How do I get the IP address?
Posted: 06 Aug 2014 12:27
by angelatwork
Good to know, thank you Martin!
Re: How do I get the IP address?
Posted: 07 Oct 2016 06:16
by evebrea
Martin wrote:Hi,
There is no built-in action to get the IP address but you can use following actions to get the information:
-action Execute Command: netcfg
or for one interface
-action Execute Command: ifconfig wlan0 resp. Execute Command: ifconfig rmnet0
The action will store the output in a variable called stdout. You have to use a script and functions to extract the part you are interested in.
For example:
-action Execute Command: ifconfig wlan0
This stores the following text in variable stdout:
wlan0: ip 192.168.1.45 mask 255.255.255.0 flags [up broadcast running multicast]
use an action script to split the text on the whitespace characters into words/tokens:
tokens = split(stdout, "\\s");
then use function getElement to store the third word in a variable called ip:
ip = getElement(tokens, 2);
display the variable ip on screen:
-action Notification on Screen: {ip}
You can also combine the scripts directly into the notification but it's much harder to debug when something goes wrong:
-action Notification on Screen: {getElement(split(stdout, "\\s"), 2)}
Regards,
Martin
Sorry to bother, but i don't have a huge grasp of scripts. Could you put this into a basic/example flow i can download and modify hands-on?
Re: How do I get the IP address?
Posted: 07 Oct 2016 19:31
by Martin
Following flow might work:
Show IP
Please note that the output of the ifconfig command could be different on your device so I can't guarantee that the regular expression works on your device.
Regards,
Martin
Re: How do I get the IP address?
Posted: 08 Oct 2016 00:23
by evebrea
Martin wrote:Following flow might work:
Show IP
Please note that the output of the ifconfig command could be different on your device so I can't guarantee that the regular expression works on your device.
Regards,
Martin
worked just fine, made "notification on screen" of my IP
Re: How do I get the IP address?
Posted: 08 Oct 2016 02:02
by evebrea
Martin wrote:Following flow might work:
Show IP
Please note that the output of the ifconfig command could be different on your device so I can't guarantee that the regular expression works on your device.
Regards,
Martin
Correction. It's only working on wifi. on regular net it throws an error
"invalid index 1, size is 0" (expression: groups[1][line2]
Re: How do I get the IP address?
Posted: 10 Oct 2016 18:35
by Martin
You can use the command
ifconfig without options to show all available interfaces and adapt the example accordingly.
You could also use a page like this to get the external IP address:
http://ipv4bot.whatismyipaddress.com/
Regards,
Martin