Send notification if public IP for router changed

Post new topic   Reply to topic    DD-WRT Forum Index -> Broadcom SoC based Hardware
Author Message
newnews
DD-WRT User


Joined: 14 Feb 2010
Posts: 86

PostPosted: Thu Aug 18, 2016 19:20    Post subject: Send notification if public IP for router changed Reply with quote
Hello,

I have VPN server set up on my dd-wrt router. The public router ip does not change usually. However, in case that ISP assigns a new IP address to my router, can I get immediate notification with new IP address information by email or other method so I can update the ip address on my remote client? Thanks
Sponsor
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 12917
Location: Netherlands

PostPosted: Thu Aug 18, 2016 19:38    Post subject: Re: Send notification if public IP for router changed Reply with quote
Maybe someone can come up with an easier solution but you can setup a dynamic DNS with ddwrt.
Then let the DNS provider notify you when the IP address changes

newnews wrote:
Hello,

I have VPN server set up on my dd-wrt router. The public router ip does not change usually. However, in case that ISP assigns a new IP address to my router, can I get immediate notification with new IP address information by email or other method so I can update the ip address on my remote client? Thanks

_________________
Routers:Netgear R7000, R6400v1, R6400v2, EA6900 (XvortexCFE), E2000, E1200v1, WRT54GS v1.
Install guide R6400v2, R6700v3,XR300:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800/XR500: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
newnews
DD-WRT User


Joined: 14 Feb 2010
Posts: 86

PostPosted: Thu Aug 18, 2016 21:30    Post subject: Re: Send notification if public IP for router changed Reply with quote
egc wrote:
Maybe someone can come up with an easier solution but you can setup a dynamic DNS with ddwrt.
Then let the DNS provider notify you when the IP address changes

newnews wrote:
Hello,

I have VPN server set up on my dd-wrt router. The public router ip does not change usually. However, in case that ISP assigns a new IP address to my router, can I get immediate notification with new IP address information by email or other method so I can update the ip address on my remote client? Thanks


I try to avoid using Dynamic DNS.
HalfBit
DD-WRT Guru


Joined: 04 Sep 2009
Posts: 776
Location: AR, USA

PostPosted: Sat Aug 20, 2016 2:59    Post subject: Reply with quote
Creating a simple script to get the wan_ipaddr from nvram and compare it to a text file with last known IP address saved seems simple enough:
1. nvram get wan_ipaddr
2. get wan_ipaddr.txt
3. if they are equal, exit
4. if they are different, alert and exit.

The sendmail portion I know is possible as well, but I've not done that myself as I don't want to have my email password saved in a conf file somewhere. I guess if you created an email address specific for these alerts, that wouldn't be so bad.

_________________
R7000 Nighthawk - DD-WRT v3.0-r50308
R7000 Nighthawk - DD-WRT v3.0-r50308
~~~~~~~~~~Dismantled for learning opportunities~~~~~~~~~~
WRT54Gv2
WRT54Gv8.2
~~~~~~~~~~Other Settings~~~~~~~~~
https://nextdns.io/?from=2d3sq39x
https://pi-hole.net/
https://github.com/DNSCrypt/dnscrypt-proxy
Acumen
DD-WRT User


Joined: 15 Nov 2014
Posts: 221

PostPosted: Sat Aug 20, 2016 10:32    Post subject: Reply with quote
HalfBit wrote:
Creating a simple script to get the wan_ipaddr from nvram and compare it to a text file with last known IP address saved seems simple enough:
1. nvram get wan_ipaddr
2. get wan_ipaddr.txt
3. if they are equal, exit
4. if they are different, alert and exit.

The sendmail portion I know is possible as well, but I've not done that myself as I don't want to have my email password saved in a conf file somewhere. I guess if you created an email address specific for these alerts, that wouldn't be so bad.
Is your DDWRT connected directly to the Web or does it have a LAN connection to your ISP Router?

If directly connected, the solution above is the best way.
Sending a mail message can be done by (if no password is required):
Code:
echo "Subject: DDWRT WAN IP Change" | cat - <some text file as body> | sendmail -f<from email> -d"<domain from email>" -S<smtp server>:<tcp port> <to email address>


If DDWRT is not connected to the Web directly, the best way probably is to use some external server that returns your public IP address. For example:
Code:
PubIP=$(wget -T 10 https://ipinfo.io/ip -qO -)

Compare the stored and the received address and if not equal, store the new address in a file and send a message.

_________________
Netgear WNDR4300v1 DD-WRT v3.0 BS r29837 | Netgear R6400 DD-WRT v3.0 KB r33525M | Tickets: 5429
IPv4 & IPv6-PD | ProFTP & Samba to USB thumb | DNSMasq DHCPv6 | Pi-Hole on RasPi

Found a bug, report it so the it can be fixed: http://svn.dd-wrt.com/
HalfBit
DD-WRT Guru


Joined: 04 Sep 2009
Posts: 776
Location: AR, USA

PostPosted: Sat Aug 20, 2016 15:24    Post subject: Reply with quote
Acumen wrote:
Is your DDWRT connected directly to the Web or does it have a LAN connection to your ISP Router?

If directly connected, the solution above is the best way.
Sending a mail message can be done by (if no password is required):
Code:
echo "Subject: DDWRT WAN IP Change" | cat - <some text file as body> | sendmail -f<from email> -d"<domain from email>" -S<smtp server>:<tcp port> <to email address>


If DDWRT is not connected to the Web directly, the best way probably is to use some external server that returns your public IP address. For example:
Code:
PubIP=$(wget -T 10 https://ipinfo.io/ip -qO -)

Compare the stored and the received address and if not equal, store the new address in a file and send a message.

One correction--http works, not https...at least when I tested it out of curiosity:
Code:
PubIP=$(wget -T 10 http://ipinfo.io/ip -qO -)

Alternatively, I got curl to work with the following:
Code:
curl --capath /opt/usr/bin/ --cacert /opt/usr/bin/ca-bundle.crt https://ipinfo.io/ip

If you don't want to figure out the Cert CA bundle, you can just ignore any cert errors by doing:
Code:
curl -k https://ipinfo.io/ip

Pretty cool, thanks for sharing.

_________________
R7000 Nighthawk - DD-WRT v3.0-r50308
R7000 Nighthawk - DD-WRT v3.0-r50308
~~~~~~~~~~Dismantled for learning opportunities~~~~~~~~~~
WRT54Gv2
WRT54Gv8.2
~~~~~~~~~~Other Settings~~~~~~~~~
https://nextdns.io/?from=2d3sq39x
https://pi-hole.net/
https://github.com/DNSCrypt/dnscrypt-proxy
newnews
DD-WRT User


Joined: 14 Feb 2010
Posts: 86

PostPosted: Mon Aug 22, 2016 20:51    Post subject: Reply with quote
HalfBit wrote:
Creating a simple script to get the wan_ipaddr from nvram and compare it to a text file with last known IP address saved seems simple enough:
1. nvram get wan_ipaddr
2. get wan_ipaddr.txt
3. if they are equal, exit
4. if they are different, alert and exit.

The sendmail portion I know is possible as well, but I've not done that myself as I don't want to have my email password saved in a conf file somewhere. I guess if you created an email address specific for these alerts, that wouldn't be so bad.


Thanks, do you have other alert option other then email?
newnews
DD-WRT User


Joined: 14 Feb 2010
Posts: 86

PostPosted: Mon Aug 22, 2016 20:52    Post subject: Reply with quote
Acumen wrote:
HalfBit wrote:
Creating a simple script to get the wan_ipaddr from nvram and compare it to a text file with last known IP address saved seems simple enough:
1. nvram get wan_ipaddr
2. get wan_ipaddr.txt
3. if they are equal, exit
4. if they are different, alert and exit.

The sendmail portion I know is possible as well, but I've not done that myself as I don't want to have my email password saved in a conf file somewhere. I guess if you created an email address specific for these alerts, that wouldn't be so bad.
Is your DDWRT connected directly to the Web or does it have a LAN connection to your ISP Router?

If directly connected, the solution above is the best way.
Sending a mail message can be done by (if no password is required):
Code:
echo "Subject: DDWRT WAN IP Change" | cat - <some text file as body> | sendmail -f<from email> -d"<domain from email>" -S<smtp server>:<tcp port> <to email address>


If DDWRT is not connected to the Web directly, the best way probably is to use some external server that returns your public IP address. For example:
Code:
PubIP=$(wget -T 10 https://ipinfo.io/ip -qO -)

Compare the stored and the received address and if not equal, store the new address in a file and send a message.


Thank you, I will try it using email first
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> Broadcom SoC based Hardware All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum