How do I get the IP address?

Post your questions and help other users.

Moderator: Martin

abbood99
Posts: 2
Joined: 11 Oct 2013 13:49

How do I get the IP address?

Post by abbood99 » 15 Oct 2013 05:19

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.

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: How do I get the IP address?

Post by Martin » 15 Oct 2013 16:09

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

abbood99
Posts: 2
Joined: 11 Oct 2013 13:49

Re: How do I get the IP address?

Post by abbood99 » 15 Oct 2013 20:26

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,,,,

sambarlick
Posts: 96
Joined: 27 Jul 2014 10:40

Re: How do I get the IP address?

Post by sambarlick » 03 Aug 2014 16:55

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

angelatwork
Posts: 186
Joined: 12 Feb 2014 01:45

Re: How do I get the IP address?

Post by angelatwork » 06 Aug 2014 12:27

Good to know, thank you Martin!
Best regards,
AngelAtwOrk

evebrea
Posts: 116
Joined: 12 Aug 2013 15:28

Re: How do I get the IP address?

Post by evebrea » 07 Oct 2016 06:16

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?

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: How do I get the IP address?

Post by Martin » 07 Oct 2016 19:31

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

evebrea
Posts: 116
Joined: 12 Aug 2013 15:28

Re: How do I get the IP address?

Post by evebrea » 08 Oct 2016 00:23

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

evebrea
Posts: 116
Joined: 12 Aug 2013 15:28

Re: How do I get the IP address?

Post by evebrea » 08 Oct 2016 02:02

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]

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: How do I get the IP address?

Post by Martin » 10 Oct 2016 18:35

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

Post Reply