Advertisement
Guest User

Untitled

a guest
Dec 18th, 2017
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. :local username "<dyn.com user name>"
  2. :local password "<dyn.com password or, better, Updater Client Key>"
  3. :local hostname "<dyn.com host name>"
  4. :local emailAddress "<where to send notifications>"
  5.  
  6. :local url "dummy"
  7. :local previousIP
  8.  
  9. :global dyndnsForce
  10.  
  11. :set dyndnsForce false
  12.  
  13. :log info ("UpdateDynDNS starts.")
  14.  
  15. # print some debug info
  16. #:log info ("UpdateDynDNS: username = $username")
  17. #:log info ("UpdateDynDNS: password = $password")
  18. #:log info ("UpdateDynDNS: hostname = $hostname")
  19. #:log info ("UpdateDynDNS: previousIP = $previousIP")
  20.  
  21. # I have some doubt over the persistence of the global previousIP.
  22. # This value should be stored in /dyndns.txt after the last update attempt,
  23. # preceded by the status and a space.
  24. # For status values see: https://help.dyn.com/remote-access-api/return-codes/
  25.  
  26. :if ([:len [/file find name=dyndns.txt]] > 0) do={
  27. :local ipfile [/file get dyndns.txt contents]
  28. :local ipstart ([find $ipfile " " -1] + 1)
  29. :local ipend [:len $ipfile]
  30. :set previousIP [:pick $ipfile $ipstart $ipend]
  31. } else={
  32. :set previousIP "0.0.0.0"
  33. }
  34.  
  35. # get the current IP address from the internet (in case of double-nat)
  36. /tool fetch mode=http address="checkip.dyn.com" src-path="/" dst-path="/dyndns.checkip.html"
  37. :delay 1
  38. :local result [/file get dyndns.checkip.html contents]
  39.  
  40. # parse the current IP result
  41. :local resultLen [:len $result]
  42. :local startLoc [:find $result ": " -1]
  43. :set startLoc ($startLoc + 2)
  44. :local endLoc [:find $result "</body>" -1]
  45. :local currentIP [:pick $result $startLoc $endLoc]
  46.  
  47. # Remove the # on next line to force an update every single time - useful for debugging,
  48. # but you could end up getting blacklisted by DynDNS!
  49.  
  50. #:set dyndnsForce true
  51.  
  52. # Determine if dyndns update is needed
  53. # more dyndns updater request details http://www.dyndns.com/developers/specs/syntax.html
  54.  
  55. :if (($currentIP != $previousIP) || ($dyndnsForce = true)) do={
  56. :log info ("Changing IP from $previousIP to $currentIP.")
  57. :set dyndnsForce false
  58. :set url "http://$username:$password@members.dyndns.org/nic/update?hostname=$hostname&myip=$currentIP&wildcard=no"
  59. /tool fetch url=$url mode=http dst-path="/dyndns.txt"
  60.  
  61. # Original code:
  62. # /tool fetch user=$username password=$password mode=http address="members.dyndns.org" \
  63. # src-path="nic/update?system=dyndns&hostname=$hostname&myip=$currentIP&wildcard=no" \
  64. # dst-path="/dyndns.txt"
  65.  
  66. :delay 1
  67.  
  68. # :set previousIP $currentIP
  69.  
  70. :local result [/file get dyndns.txt contents]
  71. :log info ("UpdateDynDNS: Dyndns update needed")
  72. :log info ("UpdateDynDNS: Dyndns Update Result: ".$result)
  73.  
  74. # email result:
  75. :local output "DynDNS Update Result: $result"
  76. /tool e-mail send to="$emailAddress" subject="DynDNS update $currentTime" body="$output"
  77. } else={
  78. :log info ("UpdateDynDNS: No dyndns update needed")
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement