1. Download our Official Android App: Forums for Android!

Tips [Profile] Use Tasker to update Google Domains DynDNS

Discussion in 'Android Apps & Games' started by codesplice, Jan 15, 2015.

  1. codesplice

    codesplice Elite Recognized Moderator
    Moderator Thread Starter
    Rank:
     #16
    Points:
    1,563
    Posts:
    8,897
    Joined:
    Oct 29, 2013

    Oct 29, 2013
    8,897
    10,395
    1,563
    Male
    SysAdmin
    Huntsville, AL
    I whipped up a profile that I'm fairly pleased with... since Google Domains just added dynamic DNS support (as well as an API for updating the records), I created a Tasker profile to automatically update a DynDNS record for my phone whenever it's connected to Wifi. It's not a particularly useful profile (unless you plan on hosting a website on your phone? I'm not going to judge) but it was a fun challenge to put together. Besides, it's been a while since I've whipped up a profile from scratch.

    I also figured this was a good time to start using that domain name I purchased for something - a wild blog post appears!

    Anyhoo, here are the deets:

    Code (Text):
    1.  
    2. Profile: DynDNS
    3.  
    4. Notification: no
    5.  
    6. State: Wifi Connected [ SSID:* MAC:* IP:* ]
    7.  
    8. Enter: DDNS
    9.  
    10. A1: Wait [ MS:0 Seconds:5 Minutes:0 Hours:0 Days:0 ]
    11.  
    12. A2: HTTP Get [ Server:Port:http://ipv4.icanhazip.com/ Path: Attributes: Cookies: User Agent: Timeout:20 Mime Type: Output File: Trust Any Certificate:Off ]
    13.  
    14. A3: If [ %HTTPD !~ %PUB_IP ]
    15.  
    16. A4: Variable Set [ Name:%PUB_IP To:%HTTPD Do Maths:Off Append:Off ]
    17.  
    18. A5: HTTP Post [ Server:Port:https://username:password@domains.google.com Path:/nic/update?hostname=nexusXXXXX.codesplice.net&myip=%PUB_IP Data / File: Cookies: User Agent: Timeout:10 Content Type: Output File: Trust Any Certificate:Off ]
    19.  
    20. A6: Wait [ MS:0 Seconds:0 Minutes:2 Hours:0 Days:0 ]
    21.  
    22. A7: Variable Set [ Name:%newline To:
    23. Do Maths:Off Append:Off ]
    24.  
    25. A8: Run Shell [ Command:nslookup nexusXXXXX.codesplice.net Timeout (Seconds):0 Use Root:Off Store Output In:%NSLOOKUP Store Errors In: Store Result In: ]
    26.  
    27. A9: Variable Split [ Name:%NSLOOKUP Splitter:%newline Delete Base:Off ]
    28.  
    29. A10: Notify [ Title:%NSLOOKUP4 Text:%NSLOOKUP5 Icon:hd_ab_navigation_accept Number:0 Permanent:Off Priority:1 ]
    30.  
    31. A11: Variable Clear [ Name:%NSLOOKUP* Pattern Matching:On ]
    32.  
    33. A12: End If
    Line-by-line explanations:
    1. Profile: DynDNS
      The name given to the profile.
    2. Notification: no
      This profile will be a "fire-and-forget" sort of thing, so I don't want an ongoing notification when it's active.
    3. State: Wifi Connected [ SSID:* MAC:* IP:* ]
      I'm going to attempt to update DynDNS when connected to Wifi.
    4. Enter: DDNS
      Name of the Enter (and only) Task.
    5. A1: Wait [ MS:0 Seconds:5 Minutes:0 Hours:0 Days:0 ]
      Wait 5 seconds after connecting to Wifi (to allow time to receive local DHCP IP and establish Internet connection).
    6. A2: HTTP Get [ Server:port:http://ipv4.icanhazip.com/ Path: Attributes: Cookies: User Agent: Timeout:20 Mime Type: Output File: Trust Any Certificate:Off ]
      Connect to a dead-simple service for resolving the phone's public-facing IP. icanhazip.com returns just the IP address in plain-text with no filler, which means I don't have to do any crazy string parsing (yay!). Tasker automatically stores the returned data of an HTTP GET request into the global variable %HTTPD. Only the Server:port field is required.
      [​IMG]
    7. A3: If [ %HTTPD !~ %PUB_IP ]
      I don't want to run the rest of the task (and submit repeated DynDNS updates) if the current public IP matches what I've already registered. I store the current IP in the%PUB_IP variable. For this If statement, I'm just checking to see if the HTTP GET return does not match the value of %PUB_IP. If TRUE (if it doesn't match), I run the rest of the Task; if FALSE (if it does match), I just skip to the end.
    8. A4: Variable Set [ Name:%PUB_IP To:%HTTPD Do Maths:Off Append:Off ]
      Store the public IP as %PUB_IP.
    9. A5: HTTP Post [ Server:port:https://username:password@domains.google.com Path:/nic/update?hostname=nexusXXXXX.codesplice.net&myip=%PUB_IP Data / File: Cookies: User Agent: Timeout:10 Content Type: Output File: Trust Any Certificate:Off ]
      This is the heavy lifter. Username and password should be the autogenerated values obtained from Google's Dynamic DNS Synthetic Records Creator Thing - NOT your Google credentials (pls). Replace nexusXXXXX.codesplice.net with your DynDNS record's subdomain (duh).

      [​IMG]
    10. A6: Wait [ MS:0 Seconds:0 Minutes:2 Hours:0 Days:0 ]
      I'm feeling patient, so let's wait two minutes before we check to see if the DNS change has propagated.
    11. A7: Variable Set [ Name:%newline To:
    12. Do Maths:Off Append:Off ]
      Set the local %newline variable to a newline character (carriage return - just press Enter on your Android keyboard). This will come in handy shortly.
    13. A8: Run Shell [ Command:nslookup nexusXXXXX.codesplice.net Timeout (Seconds):0 Use Root:Off Store Output In:%NSLOOKUP Store Errors In: Store Result In: ]
      Run the nslookup command against the hopefully-updated DynDNS record and store the returned data (command output) in %NSLOOKUP. The output of nslookup will look something like this:
      Code (Text):
      1.  
      2. Server: google-public-dns-a.google.com
      3. Address: 8.8.8.8
      4.  
      5. Name: nexusXXXXX.codesplice.net
      6. Address: 71.228.X.X
      7.  
    14. A9: Variable Split [ Name:%NSLOOKUP Splitter:%newline Delete Base:Off ]
      Split the variable %NSLOOKUP into multiple variables at each newline character. We're really only interested in the last two lines of the nslookup output.
    15. A10: Notify [ Title:%NSLOOKUP4 Text:%NSLOOKUP5 Icon:hd_ab_navigation_accept Number:0 Permanent:Off Priority:1 ]
      Create a low-priority notification to display the name of the DynDNS record (%NSLOOKUP4) and the public-facing IP (%NSLOOKUP5).

      [​IMG]
    16. A11: Variable Clear [ Name:%NSLOOKUP* Pattern Matching:On ]
      Clean up some of the variable mess.
    17. A12: End If
      FIN.

    Ask if you have questions or, better yet, give me some tips on what I can use this for. :D
     

    Advertisement

    Unforgiven likes this.

Share This Page

Loading...