Skip to content

Instantly share code, notes, and snippets.

@hovissimo
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hovissimo/c884eeae81c62c4780d7 to your computer and use it in GitHub Desktop.
Save hovissimo/c884eeae81c62c4780d7 to your computer and use it in GitHub Desktop.
Update Dynamic DNS service when IP address changes

Thanks to Paul Reed and his Alert flow for inspiration.

This flow is built from Paul's, but adds IP persistence via Firebase and sends a Dynamic DNS update request when the IP changes.

To use this flow, you'll need to update :

  • the Firebase nodes with your own Firebase
  • the Dynamic DNS request with your own DynDNS service (it's ready to go for Zoneedit)
  • the mqtt notifier (you can also replace these components completely)

You'll also want to install the Firebase nodes at https://github.com/hovissimo/node-red-firebase

[{"id":"3d8d2e6c.cba89a","type":"mqtt-broker","broker":"home.bunkercode.com","port":"1883","clientid":""},{"id":"b12fd22.ccb38b","type":"inject","name":"Get IP","topic":"ip","payload":"eth0","payloadType":"none","repeat":"","crontab":"00 08 * * *","once":false,"x":167,"y":247,"z":"e7bb1ba1.345a5","wires":[["49301a6a.3ebb14","cd5a5417.366988"]]},{"id":"cd5a5417.366988","type":"exec","command":"wget -qO- http://bot.whatismyipaddress.com/ ; echo","append":"","useSpawn":"","name":"wget whatismyipaddress.com","x":390,"y":278.5,"z":"e7bb1ba1.345a5","wires":[["2eb875f3.73cb92"],[],[]]},{"id":"2eb875f3.73cb92","type":"switch","name":"Integrity check","property":"payload","rules":[{"t":"regex","v":"\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b"},{"t":"else"}],"checkall":"true","outputs":2,"x":616,"y":265.5,"z":"e7bb1ba1.345a5","wires":[["97bdc2b3.6c8f88"],[]]},{"id":"109900cf.9f7077","type":"firebase query","name":"","firebaseurl":"https://busknight.firebaseio.com/nodered/home/ip/value","child":"","x":344,"y":416,"z":"e7bb1ba1.345a5","wires":[["1a43a779.8ce5c1"]]},{"id":"4892ffec.fb5e1","type":"change","action":"replace","property":"newip","from":"","to":"msg.payload","reg":false,"name":"","x":182,"y":416,"z":"e7bb1ba1.345a5","wires":[["109900cf.9f7077"]]},{"id":"1a43a779.8ce5c1","type":"function","name":"Swallow unchanged IP message","func":"var lastip = msg.payload;\nvar currentip = msg.newip;\n\nif (lastip != currentip) {\n\tmsg.payload = {\n\t\t\"value\": currentip.trim(),\n\t\t\"updated\": new Date(),\n\t};\n\treturn msg;\n} else {\n\tconsole.log(\"Dynamic DNS: IP has not changed, abort!\");\n}","outputs":1,"x":574,"y":416,"z":"e7bb1ba1.345a5","wires":[["54ed0610.b9fea","4ce6bac0.35db14"]]},{"id":"54ed0610.b9fea","type":"firebase modify","name":"","firebaseurl":"https://busknight.firebaseio.com/nodered/home/ip","child":"","method":"update","x":867,"y":417,"z":"e7bb1ba1.345a5","wires":[]},{"id":"4ce6bac0.35db14","type":"http request","name":"Update zoneedit","method":"GET","url":"https://dynamic.zoneedit.com/auth/dynamic.html?zones=bunkercode.com","x":386,"y":543,"z":"e7bb1ba1.345a5","wires":[["963dc28f.f4582","d6000748.79e4c8"]]},{"id":"963dc28f.f4582","type":"switch","name":"","property":"payload","rules":[{"t":"regex","v":"2\\d\\d"},{"t":"else"}],"checkall":"false","outputs":2,"x":566,"y":543,"z":"e7bb1ba1.345a5","wires":[["17d31a4d.dce036","d133fc9d.b3509"],["d133fc9d.b3509","7fcf8740.e0f858"]]},{"id":"17d31a4d.dce036","type":"file","name":"","filename":"dyndns.log","appendNewline":true,"overwriteFile":false,"x":710,"y":509,"z":"e7bb1ba1.345a5","wires":[]},{"id":"d133fc9d.b3509","type":"debug","name":"Dynamic DNS update results","active":true,"console":"true","complete":"true","x":767,"y":543,"z":"e7bb1ba1.345a5","wires":[]},{"id":"dc4ac786.89d63","type":"debug","name":"Notice","active":true,"console":"true","complete":"false","x":515,"y":222,"z":"e7bb1ba1.345a5","wires":[]},{"id":"49301a6a.3ebb14","type":"change","action":"replace","property":"payload","from":"","to":"Running Dynamic DNS flow...","reg":false,"name":"","x":351,"y":222,"z":"e7bb1ba1.345a5","wires":[["dc4ac786.89d63"]]},{"id":"7fcf8740.e0f858","type":"mqtt out","name":"","topic":"/hovis/notify","broker":"3d8d2e6c.cba89a","x":711,"y":583,"z":"e7bb1ba1.345a5","wires":[]},{"id":"cbc88ce1.7d115","type":"inject","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":184,"y":540,"z":"e7bb1ba1.345a5","wires":[["4ce6bac0.35db14"]]},{"id":"d6000748.79e4c8","type":"debug","name":"","active":true,"console":false,"complete":false,"x":584,"y":625,"z":"e7bb1ba1.345a5","wires":[]},{"id":"97bdc2b3.6c8f88","type":"function","name":"trim","func":"msg.payload = msg.payload.trim();\nreturn msg;","outputs":1,"x":766,"y":259,"z":"e7bb1ba1.345a5","wires":[["4892ffec.fb5e1"]]}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment