Get Ip address Every Morning

2,017 views
Skip to first unread message

Brad Mai

unread,
Jan 29, 2013, 7:45:11 PM1/29/13
to tas...@googlegroups.com
All I would like to do is get my home ip address everymorning before i leave for work and store the date and the ip address in a file.

But it outputs a whole page of useless stuff.

Can someone help me please

thanks!

bdanders

unread,
Jan 30, 2013, 1:45:10 PM1/30/13
to tas...@googlegroups.com
Try running the shell command:

ifconfig rmnet0

On my phone that gives me a fairly short string that includes the ip address. If you're on wifi, I think you need to change the "rmnet0". The command 'netcfg' also seems to include some useful stuff. I'm sure this all depends on your phone and ROM, but it's worth checking out.

bdanders

unread,
Jan 30, 2013, 1:47:52 PM1/30/13
to tas...@googlegroups.com
"dumpsys connectivity" also outputs a wealth of useful information.


On Tuesday, January 29, 2013 7:45:11 PM UTC-5, Brad Mai wrote:

bdanders

unread,
Jan 30, 2013, 7:13:24 PM1/30/13
to tas...@googlegroups.com
 On wifi the command is:

ifconfig wlan0

Brad Mai

unread,
Jan 30, 2013, 7:33:12 PM1/30/13
to tas...@googlegroups.com
I've never ran a shell command. I'm not sure how.

BossMan

unread,
Jan 30, 2013, 8:13:03 PM1/30/13
to tas...@googlegroups.com
It can be tiwlan0 as well, I believe.

The other command you could try is 'getprop' (e.g. 'getprop | grep ipaddress')

A.

Brad Mai

unread,
Jan 30, 2013, 9:13:16 PM1/30/13
to tas...@googlegroups.com
How do i run these commands in tasker?

bdanders

unread,
Jan 30, 2013, 10:58:37 PM1/30/13
to tas...@googlegroups.com
Select Action, Script, Run shell.
Command: ifconfig wlan0 (or whatever command you need)
Put whatever variable you want in the "Store Output In" field. Use variable split commands to get just the IP address.

Dan

unread,
Jan 31, 2013, 3:51:09 AM1/31/13
to tas...@googlegroups.com
You could also try to use Secure Settings (get it from Google Play).

My GetIPAddress Task for WLAN looks like this:

GetIPAddress (2)
A1: Variable Clear [ Name:%MyIP Pattern Matching:Off ]
A2: Secure Settings [ Configuration:GetIPAddress Package:com.intangibleobject.securesettings.plugin Name:Secure Settings Continue Task After Error:On ]
A3: Wait Until [ MS:0 Seconds:4 Minutes:0 Hours:0 Days:0 ] If [ %MyIP Is Set ]
A4: Flash [ Text:%MyIP Long:Off ] 

When you have installed Secure Settings, it is accessible as a Plugin in Tasker. Add it and Edit the configuration

Run Command is:
ifconfig wlan0 | awk -F " " '{print $3}'

Wait for the process checked   (actually A3 above might not be needed because of this...)
Output Variable %MyIP
Save

After running this task, the global variable %MyIP is available with the IP address of the WLAN connection. I usually call this task from within another task. I have not added a lot of error checking, nor did I make it work on Mobile connections, but its probably a good idea to work on that. So far I did not take the time to make GetIPAddress really foolproof and universal. Anyone volunteering? ;-)

Dan

I "stole" the idea from another post, but can't remember from where.

 

Dan

unread,
Jan 31, 2013, 4:08:18 AM1/31/13
to tas...@googlegroups.com
Good Idea... let's see..

GetIPAddress2 (111)
A1: Variable Clear [ Name:%MyIPAddress Pattern Matching:Off ]
A2: Run Shell [ Command:ifconfig wlan0 Timeout (Seconds):4 Use Root:Off Store Result In:%ifconfig ]
A3: Variable Split [ Name:%ifconfig Splitter: Delete Base:Off ]
A4: Variable Set [ Name:%MyIPAddress To:%ifconfig3 Do Maths:Off Append:Off ]

%MyIPAddress contains the wlan address... 

Simpler than Secure Settings and does not need a plugin.. hmm..

Dan

Brad Mai

unread,
Jan 31, 2013, 6:10:55 PM1/31/13
to tas...@googlegroups.com
Thanks Dan, i tried what you said and its not working.
the last step I added was write file with %MyIPAddress and also %ipconfig3
My file is still empty

Dan

unread,
Feb 1, 2013, 3:48:41 AM2/1/13
to tas...@googlegroups.com
Hi Brad,
Which solution do you use now?
Have you looked at the variable and does it contain the IP address? If yes, there is probably an issue with writing to the file. 
Perhaps you can post your profile and the tasks...
Dan

bdanders

unread,
Feb 1, 2013, 8:58:26 AM2/1/13
to tas...@googlegroups.com
What, if anything, does the shell command "netcfg" output for you? If you have a terminal emulator app you can test these commands there to see what works.

tlamik

unread,
Feb 1, 2013, 12:26:43 PM2/1/13
to tas...@googlegroups.com
on SGS3 and maybe on others too ifconfig (linux cmd) works fine. I am not sure if the root is necessary or not. Try some kind of terminal emulator and there You can "tune" the right command. In my case it is:
/system/xbin/ifconfig wlan0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print

that command will show the current IP address in terminal. In Tasker You can use a Secure Settings plugin to save the output of that massega to some variable.

Dne pátek, 1. února 2013 14:58:26 UTC+1 bdanders napsal(a):

Brad Mai

unread,
Feb 1, 2013, 3:46:39 PM2/1/13
to tas...@googlegroups.com
I will post what I have once I get home.
I have a sgs3 phone, I was hoping there was something simple to run at say 6am every morning and it will get the ip and store it in a file on my sd. So far it doesn't seem to be that simple.

The last task I made was something to keep track of my work hours, so when I connect to my works wifi it puts the time in %PINTIME then the exit task sets %POTIME ( which will be punch in time and punch out time) then also on the exit task it will write the date, punch in time and punch out time in a txt file.

That's pretty much how advanced I am with tasker. So I will need a lot of help.
Thanks for every one helping me!

tlamik

unread,
Feb 2, 2013, 6:44:10 AM2/2/13
to tas...@googlegroups.com
Please note You will need Busybox installed to use /system/xbin/ifconfig and awk 

Dne pátek, 1. února 2013 21:46:39 UTC+1 Brad Mai napsal(a):

Brad Mai

unread,
Feb 2, 2013, 12:54:50 PM2/2/13
to tas...@googlegroups.com
Busy box requires root, correct?

tlamik

unread,
Feb 2, 2013, 1:02:08 PM2/2/13
to tas...@googlegroups.com
Correct

Dne sobota, 2. února 2013 18:54:50 UTC+1 Brad Mai napsal(a):
Busy box requires root, correct?

bdanders

unread,
Feb 2, 2013, 11:38:46 PM2/2/13
to tas...@googlegroups.com
You don't need busybox or root to use the simple "ifconfig wlan0" command. I just did it on my wife's bone stock SGS3. Just use Tasker's built in variable split functions instead of awk to get the IP address.

Jiri Harcarik

unread,
Feb 3, 2013, 4:07:04 AM2/3/13
to tas...@googlegroups.com

Yes, correct. You have right. I tried it with Taker variable split and variable select and it seems works,  but I have rooted phone so I'll stay using Busybox cmds

Brad Mai

unread,
Feb 3, 2013, 6:13:37 PM2/3/13
to tas...@googlegroups.com
Good Idea... let's see..

GetIPAddress2 (111)
A1: Variable Clear [ Name:%MyIPAddress Pattern Matching:Off ] 
A2: Run Shell [ Command:ifconfig wlan0 Timeout (Seconds):4 Use Root:Off Store Result In:%ifconfig ] 
A3: Variable Split [ Name:%ifconfig Splitter: Delete Base:Off ] 
A4: Variable Set [ Name:%MyIPAddress To:%ifconfig3 Do Maths:Off Append:Off ] 

%MyIPAddress contains the wlan address... 

Simpler than Secure Settings and does not need a plugin.. hmm..

Dan
- hide quoted text -

I used this methode, but A5 will have Write File [ip3.txt Text:%MyIPAddress %ipconfig3 Append:On Add New Line: On
It doesnt put anything into the txt file

Dan

unread,
Feb 4, 2013, 3:47:15 AM2/4/13
to tas...@googlegroups.com
According to bdanders, ifconfig should work on unrooted phones too. So, in either case (unrooted or rooted phone), ifconfig wlan0 should give you something back
Have you checked with Flash or Popup (in Tasker Alerts) if the variables %ifconfig, %ifconfig3 and %MyIPAddress are actualy filled with anything?

If not, you might have misspelled "ifconfig wlan0" in the shell command. The second parameter (wlan0) is the name of the interface. If that interface name is spelled wrong, ifconfig does not produce any output.
You could create a task that executes "netcfg" (without quotes and without parameter) instead of ifconfig. That will give you all the network interfaces listed. Check for the one that contains your IP address and is flagged "UP". 
I am not sure if on certain devices the WLAN interface might have another name? Usually it's wlan0...

Dan

Jiri Harcarik

unread,
Feb 4, 2013, 3:52:29 AM2/4/13
to tas...@googlegroups.com

Maybe it's empty cos You are using ipconfig3 for write instead of previously ifconfig3... IMHO it's misspellings

Dne 4.2.2013 0:13 "Brad Mai" <brad...@gmail.com> napsal(a):
--
You received this message because you are subscribed to the Google Groups "Tasker" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tasker+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Dan

unread,
Feb 4, 2013, 4:18:53 AM2/4/13
to tas...@googlegroups.com
Good catch tlamik. I overlooked that typo.
On the other hand, if %MyIPAddress is filled with something, there should be a line like
192.168.1.33 %ipconfig3
in the ip3.txt file.
Or, if %MyAddress is not set, there should be a line like
%MyIPAddress %ipconfig3
in the ip3.txt file. 
Or am I mistaken?

In any case, Brad. You should post your profile. It helps a lot to understand where problems are..
Dan


On Monday, February 4, 2013 9:52:29 AM UTC+1, tlamik wrote:

Maybe it's empty cos You are using ipconfig3 for write instead of previously ifconfig3... IMHO it's misspellings

I used this methode, but A5 will have Write File [ip3.txt Text:%MyIPAddress %ipconfig3 Append:On Add New Line: On

bdanders

unread,
Feb 4, 2013, 9:46:25 AM2/4/13
to tas...@googlegroups.com
Unless he also misspelled the shell command as ipconfig instead of ifconfig in which case the task might be terminating right there on error. Try checking "continue task after error" in the shell action and adding a few flash actions in there to debug what's going on.

tlamik

unread,
Feb 4, 2013, 1:56:38 PM2/4/13
to tas...@googlegroups.com
Nope. IMHO if You have an empty variable then You have an empty output of that, not %MyIPAddress but  empty space or nothing.
I've saw in the manual (I thought) that the variables without a capital letters cannot be used in other tasks or later 
so because of that I allways have variables with capital letters
maybe it's not necessary, but I'm using it in that way

Dne pondělí, 4. února 2013 10:18:53 UTC+1 Dan napsal(a):

Dan

unread,
Feb 4, 2013, 2:55:17 PM2/4/13
to tas...@googlegroups.com
Well, try it tlamik... I think you are right. but when I try it, I get the output I described.

When it comes to variables, I always use small letter variables as long it is only needed within a task. That is the case here. Otherwise the global variables list is getting cluttered. My times as (lousy) programmer is long past, but I believe it's better to use local variables for local use. 

And, LOL.. by the way.. typo's are one of the major reasons for MY issues with programming,... smile.. as you can see in my last post... 
One of the reasons I'd love to see a way to write Tasker Profiles/Tasks offline. Too often that genius Android Swiftkey keyboard thinks I am writing an email to a friend instead of Tasker variables and such...

dan

BossMan

unread,
Feb 4, 2013, 3:11:13 PM2/4/13
to tas...@googlegroups.com


Nope. IMHO if You have an empty variable then You have an empty output of that, not %MyIPAddress but  empty space or nothing.
Not true. It a variable is not defined, it's name will be shown. Try Alert->Flash %MyEmptyVar.
 
I've saw in the manual (I thought) that the variables without a capital letters cannot be used in other tasks or later 
so because of that I allways have variables with capital letters
maybe it's not necessary, but I'm using it in that way
You don't need to. As long as a variable is not all lower-case, it'll be a global variable. 

A.

Brad Mai

unread,
Feb 4, 2013, 8:01:49 PM2/4/13
to tas...@googlegroups.com
Okay, it was misspelled! I'm so sorry everyone.

Now my output is my router ip.
Is there a way to get my public ip?

Brad Mai

unread,
Feb 4, 2013, 8:07:23 PM2/4/13
to tas...@googlegroups.com
Profile: Ipget (38)
Time: From 18:03 Till 18:04
Enter: Anon (46)
A1: Variable Clear [ Name:%MYIPADDRESS Pattern Matching:Off ]
A2: Run Shell [ Command:ifconfig wlan0 Timeout (Seconds):4 Use Root:Off Store Output In:%ifconfig Store Errors In: Store Result In: ]
A3: Variable Split [ Name:%ifconfig Splitter: Delete Base:Off ]
A4: Variable Set [ Name:%MYIPADDRESS To:%ifconfig3 Do Maths:Off Append:Off ]
A5: Write File [ File:Ip3.txt Text:%MYIPADDRESS Append:On Add Newline:On ]

nanobrain

unread,
Feb 4, 2013, 8:22:57 PM2/4/13
to tas...@googlegroups.com
Go to this website: http://checkip.dyndns.org/ and parse the results 

Brad Mai

unread,
Feb 4, 2013, 8:58:36 PM2/4/13
to tas...@googlegroups.com
Getip (13)
A1: HTTP Get [ Server:Port:http://checkip.dyndns.org/ Path: Attributes: Cookies: Timeout:10 Mime Type: Output File:Ipget.txt ]

This has the ip, but it also has other stuff I don't want. By parsing do you mean only select ip address? If so, how would I do it?

Dan

unread,
Feb 5, 2013, 2:31:27 AM2/5/13
to tas...@googlegroups.com
I do not think you get the router IP with the code you provided. You will get the IP address of your Android devices wlan0 interface.

Dan

unread,
Feb 5, 2013, 2:41:59 AM2/5/13
to tas...@googlegroups.com
Check Variable Split in tasker and consult the userguide and the Tasker Wiki.

tlamik

unread,
Feb 5, 2013, 1:51:47 PM2/5/13
to tas...@googlegroups.com

VerIP (116)
A1: Run Shell [ Command:wget http://checkip.dyndns.org/ -O - Timeout (Seconds):2 Use Root:Off Store Result In:%VerIP Continue Task After Error:On ]
A2: Variable Split [ Name:%VerIP Splitter:: Delete Base:Off ]
A3: Variable Split [ Name:%VerIP2 Splitter:< Delete Base:Off ]
A4: Flash [ Text:%VerIP21 Long:Off ] 


Dne úterý, 5. února 2013 2:58:36 UTC+1 Brad Mai napsal(a):

Brad Mai

unread,
Feb 5, 2013, 10:19:08 PM2/5/13
to tas...@googlegroups.com
VerIP (49)
A1: Run Shell [ Command:wget http://checkip.dyndns.org/ -O - Timeout (Seconds):2 Use Root:Off Store Output In: Store Errors In: Store Result In:%VerIP Continue Task After Error:On ]
A2: Variable Split [ Name:%VerIP Splitter:: Delete Base:Off ]
A3: Variable Split [ Name:%VerIP2 Splitter:< Delete Base:Off ]
A4: Write File X [ File:VerIP.txt Text:%VerIP1 Append:On Add Newline:On ]
A5: Flash [ Text:%VarIP21 Long:Off ]

Brad Mai

unread,
Feb 5, 2013, 10:22:56 PM2/5/13
to tas...@googlegroups.com
A5 has been corrected to ver

Brad Mai

unread,
Feb 5, 2013, 10:23:49 PM2/5/13
to tas...@googlegroups.com
Wondering why a2 and a3 are purple

Brad Mai

unread,
Feb 14, 2013, 7:56:42 PM2/14/13
to tas...@googlegroups.com
Getip (15)
A1: HTTP Get X [ Server:Port:http://checkip.dyndns.org/ Path: Attributes: Cookies: Timeout:10 Mime Type: Output File:Getip.txt ]
A2: Run Shell [ Command:wget http://checkip.dyndns.org/ -O - Timeout (Seconds):2 Use Root:Off Store Result In:%VerIP Continue Task After Error:On ]
A3: Variable Split [ Name:%VerIP Splitter:: Delete Base:Off ]
A4: Variable Split [ Name:%VerIP2 Splitter:< Delete Base:Off ]
A5: Flash [ Text:%VerIP21 Long:Off ]

Brad Mai

unread,
Feb 14, 2013, 8:00:17 PM2/14/13
to tas...@googlegroups.com
This does nothing. When i disable the varibles splitters , it flashes %VerIP21.
Where did I go wrong?

Tom Hale

unread,
Dec 17, 2014, 11:57:46 PM12/17/14
to tas...@googlegroups.com
Assuming Android reports the right IP address, these reduce the number of executed processes:

/system/xbin/ifconfig wlan0 | awk '/inet addr:/ { match($0, /[.0-9]+/); print substr($0,RSTART,RLENGTH)}'

OR

/system/xbin/ifconfig wlan0 | awk '/inet addr:/ { $0=$2; FS=":"; $0=$0; print $2}'

depending on what you find most readable :)

Replace wlan0 with tun0 for VPN

Tom Hale

unread,
Dec 17, 2014, 11:57:48 PM12/17/14
to tas...@googlegroups.com

Tom Hale

unread,
Dec 18, 2014, 4:42:53 AM12/18/14
to tas...@googlegroups.com
Hi Brad,

It might be easier to use one of:
as they only list the IP address, with no other text.

eg, Command line

Capture the IP address from Run Shell command's standard output, put it into a variable. Voila!

macknn...@gmail.com

unread,
Feb 24, 2017, 6:39:23 PM2/24/17
to Tasker
I know this is oooold, but I needed my ip address as well. Here's how I did it.

Using terminal on my Galaxy S7, I found that
   ifconfig wlan0 | grep inet 
returned: 
   inet addr:192.168.9.24  Bcast:192.168.9.255  Mask:255.255.255.0

So, I did the first split into %ifconfig
Then split %ifconfig3 again using the colon(:) character as the Splitter into %ipaddress
That stripped the addr: off, leaving just the IP address in %ipaddress.

Works perfectly every time.

A1: Variable Set [ Name:%IPADDRESS To:0.0.0.0 Recurse Variables:Off Do Maths:Off Append:Off ] 
A2: Run Shell [ Command:ifconfig wlan0|grep inet Timeout (Seconds):4 Use Root:Off Store Output In:%ifconfig Store Errors In: Store Result In: ] 
A3: Variable Split [ Name:%ifconfig Splitter: Delete Base:Off ] 
A4: Variable Set [ Name:%ifaddr To:%ifconfig3 Recurse Variables:Off Do Maths:Off Append:Off ] 
A5: Variable Split [ Name:%ifaddr Splitter:: Delete Base:Off ] 
A6: Variable Set [ Name:%IPADDRESS To:%ifaddr2 Recurse Variables:Off Do Maths:Off Append:Off ] 
A7: Popup [ Title:Ip Address Text:%IPADDRESS Background Image: Layout:Popup Timeout (Seconds):5 Show Over Keyguard:On ]

On Tuesday, January 29, 2013 at 7:45:11 PM UTC-5, Brad M wrote:
All I would like to do is get my home ip address everymorning before i leave for work and store the date and the ip address in a file.

But it outputs a whole page of useless stuff.

Can someone help me please

thanks!
Reply all
Reply to author
Forward
0 new messages