Saturday, December 19, 2015

Get your Synology NAS to notify you when your IP changes

I have a residential internet service. That means I never know when my IP address is going to change. But that is ok because I use DDNS Updater 2 in order to automatically update the DNS for my domain with the IP address of my Synology NAS when it changes. But the problem with that is DNS updates do not immediately propagate to every DNS server on the internet. It could take up to 24 hours until your domain is finally updated with the new IP.


So what I need is a script to notify me when my IP changes which I can use instead until my domain works again. I mostly need this for VPN. And off I went to write such a script:

#!/bin/sh                                                                              
ip_current=`curl -silent -L http://checkip.amazonaws.com|tail -n 1`

while :
do
    # Grab IP                                                                                                              
    ip=`curl -silent -L http://checkip.amazonaws.com|tail -n 1`
    # Compare IP                                                                                                           
    if [ "$ip" != "$ip_current" ]; then
        # Notify new IP                                                                                                    
        synodsmnotify admin "IP has changed" "New IP is $ip"
        # Set as current IP                                                                                                
        ip_current=$ip
    fi

    # Wait 20 minutes                                                                                                      
    `sleep 1200`
done

It is a pretty simple script. It will grab your current IP, and then in an infinite loop keep checking to see if it changes. If it did change, it will send a notification to admin. Then it will wait 20 minutes (1200 seconds) and check again. Since I am using Pushbullet with Synology, I get notified immediately. Having it email instead of notify would of been nice, but it would of involved more work to setup and ipkg to install a third-party program.

I called this script ip_notify.sh and placed it in /opt/local/bin. In order to get it to automatically run on boot, I put the following command in /etc/rc.local:

/bin/sh /opt/local/bin/ip_notify.sh

And that was it. Make sure the files are executable (chmod +x file_name).



20 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. I think of the drug junkie ... then I realize I'm caught in a web and I seriously need help. Now, tell me: "Where would I find Stressers Anonymous?" or is there another name? Perhaps the acronym TOSO (Tired, Overworked and Stressed Out) is the accepted jargon for stressers.
    ip stresser

    ReplyDelete
  3. Me and my companions have completely appreciated this blog.
    192.168.168.0.1

    ReplyDelete
  4. When your website or blog goes live for the first time, it is exciting. That is until you realize no one but you and your. https://192-168-i-i.com

    ReplyDelete
  5. Just pure classic stuff from you here. I have never seen such a brilliantly written article in a long time. I am thankful to you that you produced this! Cliquez-ici

    ReplyDelete
  6. This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free. meer informatie

    ReplyDelete
  7. This was a truly awesome challenge and ideally I can go to the following one. It was alot of fun and I truly had a ball..  bezoek website

    ReplyDelete
  8. I am come here first time, i find the perfect article. Thanks for sharing interesting and informative post. privacyinthenetwork

    ReplyDelete
  9. just what most individuals' desire. However, most of which have no idea of the inner thoughts and multi-step means of purchasing a fresh home privacyonline.com.br

    ReplyDelete
  10. I'm really impressed about the info you provide in your articles. If you want to invest in suits and be stress-free, then you should shake hands with us. We are providing great clothing in the most reasonable price range that you wouldn’t find anywhere else. Put your trust in us as your supplier since we are the prominent printed stickers uk You can rely on us for the clothing problems we assure you we will never let our customers down.

    ReplyDelete
  11. Grandstream PBX System- Grandstream Distributor Cameroon VDS the Grandstream distributor in  Cameroon continues to bring innovative Grandstream Products to the IP communications / Telephony market with compelling values and features. Grandstream Networks is headquartered in Brookline, Massachusetts with offices in Yealink IP Phones

    ReplyDelete
  12. Attractive information on your blog, thank you for taking the time and share with us.
    custom window cake boxes

    ReplyDelete
  13. Amazing insight you have on this, it’s nice to find a website the details so much information about different artists.
    custom toy boxes

    ReplyDelete
  14. Hello, I want to subscribe for this web site to take most up-to-date updates, thus where can i do it please help out.
    custom lipstick boxes

    ReplyDelete
  15. A very awesome blog post. We are really grateful for your blog post. You will find a lot of approaches after visiting your post. https://192-168-i-i.com/192-68-0-1/

    ReplyDelete
  16. A debt of gratitude is in order for this article extremely supportive. much appreciated. whats my ip

    ReplyDelete
  17. I love visiting sites in my free time. I have visited many sites but did not find any site more efficient than yours. Thanks for the nudge! https://192-168-i-i.com

    ReplyDelete