Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Paul-Reed
Last active September 18, 2020 19:38
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Paul-Reed/9559f217b08913702c38 to your computer and use it in GitHub Desktop.
Save Paul-Reed/9559f217b08913702c38 to your computer and use it in GitHub Desktop.
Alert if Public IP address changes

I wrote this flow to send me a push message (could be twitter, email, etc) if my home IP address changes.

My ISP issues dynamic IP addresses, so occasionally my broadband would encounter a problem, and a new IP address would be issued which triggers an alert, giving me the new IP address where I can access my home network (I must get a domain!!).

It can also give an indication of router/line problems, if the IP address changes too frequently.

The flow needs little explanation, it obtains your current public IP address via http://bot.whatismyipaddress.com/ but there are other services available - http://echoip.com/ and http://ipecho.net/plain and passes the result through a 'switch' node programmed only to accept data in the format of a IP address - regex validity check (thanks Nick). The IP address is then compared to the previous recorded IP address, and if they differ - then an alert is raised, otherwise the flow ends.

[{"id":"10febc52.c63164","type":"debug","z":"a444a9ff.e7a408","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":830,"y":4830,"wires":[]},{"id":"24b6dbdd.881184","type":"exec","z":"a444a9ff.e7a408","command":"curl bot.whatismyipaddress.com","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"Call IP - whatismyipaddress.com","x":430,"y":4780,"wires":[["5530cb08.8135e4"],[],[]]},{"id":"4adfd71d.23f778","type":"inject","z":"a444a9ff.e7a408","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":220,"y":4780,"wires":[["24b6dbdd.881184"]]},{"id":"be3dc4cd.323588","type":"function","z":"a444a9ff.e7a408","name":"Compare IP","func":"context.lastip = context.lastip || 'initial';\nvar currentip = msg.payload;\n\nif (context.lastip == 'initial') {\ncontext.lastip = currentip;\n}\nelse if (context.lastip != currentip) {\nmsg.payload = \"My current IP is \"+currentip;\ncontext.lastip = currentip;\nreturn msg;\n}","outputs":1,"x":830,"y":4780,"wires":[["10febc52.c63164"]]},{"id":"5530cb08.8135e4","type":"switch","z":"a444a9ff.e7a408","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":660,"y":4780,"wires":[["be3dc4cd.323588"],[]]}]
@Kartheek1512
Copy link

Hi,

I upgraded to a new node-red version and this flow stopped working. Can anyone help how to fix it.

@jaymlr
Copy link

jaymlr commented Sep 18, 2020

Nicely done. I am getting the IPv6 number. can I append the command to get ipv4?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment