Maverickcdn
Senior Member
WICENS - WAN IP Change Email Notification Script
v1.00 Jan 13 2021 v2.0 Oct 16,2021 v2.85 Jun 26 2022 v3.00 Sep 16 2022 v3.41 Apr 16 2023 v4.00 May 8 2024 v4.04 Jan 22 2025 v4.10 Feb 3 2025
This script is targeted at those that do not use a DDNS service but need to know if their WAN IP changes (ie. you run a VPN server etc) or you just want to know if and when your WAN IP has changed. Also has the ability to send Firmware Update Email notifications and Router Reboot Email notifications or act as a Email text file sender.
Open to any and all criticism and feedback so please let me know what you think.
Script is hosted on Github
- WAN IP change notification
- Historical WAN IPs w/observed lease times
- Call user script on WAN IP change
- Firmware update notification
- Router reboot notification
- Email Forwarder ability
- amtm Email settings sync
- GMail, Outlook, Hotmail etc
- works in Double NAT
- Supports only IPv4
Version 4 brings another re-write of the script, additions, and overall optimizations
v4.00 has limited testing so please advise of issues and I will look to resolve as time allows
Script requires being configured with your To/From Email address(es), server address/port etc. or can sync with your amtm Email config
Firmware must be 384.15 or newer, or on Johns fork 374.43_48D3j9527 or newer
To install, scripts/ssh must be enabled. Install from amtm main menu or from an SSH terminal, copy/paste
For first run, use the following to access the Menu.
Then select option 1 to create the config
After first run and starting a new terminal session, you should be able to access the menu by simply entering
Use option b to create a backup of your configured settings if ever formatting /jffs or reinstalling wicens. Saved to script directory /jffs/addons/wicens (*uninstall removes backups you must manually copy to a safe location)
In SMTP server send config type, option 4 (SMTP Plain auth) is still untested. Support for sendmail options is depreciated.
Hope people can find this script useful, and would welcome your feedback, there's already 3 user requested custom fields. I find scripting a nice escape from everyday life.


To truly test the script (built in test only tests Email function), use nano to edit the saved_wan_ip to something different (not blank) in /jffs/addons/wicens/wicens_user_config.wic and let it run with cron (default 11mins). Those taking advantage of the custom script calling function should certainly test it this way.
Feeling generous?
This script is targeted at those that do not use a DDNS service but need to know if their WAN IP changes (ie. you run a VPN server etc) or you just want to know if and when your WAN IP has changed. Also has the ability to send Firmware Update Email notifications and Router Reboot Email notifications or act as a Email text file sender.
Open to any and all criticism and feedback so please let me know what you think.
Script is hosted on Github
- WAN IP change notification
- Historical WAN IPs w/observed lease times
- Call user script on WAN IP change
- Firmware update notification
- Router reboot notification
- Email Forwarder ability
- amtm Email settings sync
- GMail, Outlook, Hotmail etc
- works in Double NAT
- Supports only IPv4
WICENS - WAN IP Change Email Notification Script
This script when configured has the ability to send Email notifications for
Option 2 WAN IP Change (IPv4 only,DualWAN disabled)
Option 5 Script can call your own script when WAN IP change occurs
Option 6 Script Updates (checks every 48hrs when enabled)
Option 7 Firmware Updates (runs with built-in firmware notification check)
Option 8 Router reboot events
Option h shows hidden options
Script can also be used to send your own text generated Email files see
forwarder instructions further below
Supports GMail, Hotmail, Outlook, ISP based Email
Supports AsusWRT-Merlin built-in amtm Email configuration import
Script will function in Double NAT scenarios but does not support Dual WAN
Dual WAN check can be on/off by entering option dwd (default: on)
SMTP Email send formats available:
curl - SSL (eg GMail port 465) # amtm default
sendmail - StartTLS v1.1 higher
sendmail - StartTLS v1 only
sendmail - SMTP plain auth (no encryption)
sendmail - ISP based (no password reqd, generally port 25)
IMPORTANT - If using GMail/Outlook you must use 2 factor authentication and
setup an assigned App password for this script to use.
IMPORTANT - Your Email address(es) are stored as plain text within this
script. Your Email password is encrypted and saved to router storage.
If you dont practice good security habits around your router ssh access,
this script might not be for you.
Script compares IP in nvram for wan0 to saved IP with wan-event connected
events and cron, cron is also a watchdog and monitors for failed Email
attempts. Should the nvram IP be invalid/private IP script will use firmware
built in getrealip.sh to retrieve your WAN IP using Google STUN server.
Router reboot Email contains last known uptime prior to reboot (saved w/cron)
and down time between power loss (last check with cron) and power up time
All cron/wan-event/services-start/update-notification entries needed for this
script are automatically created and removed with enable and disable options.
NTP sync must occur on boot for proper script function
### Technical ###
Supports being used as an Email forwarder for other scripts, in your
script call /jffs/scripts/wicens.sh send {your email.txt path here}
ie. /jffs/scripts/wicens.sh send /tmp/email.txt
Use option fe (unlisted) in the menu to view a sample Email .txt file
When using wicens as an Email forwarder you can pass a second argument after
the Email text path as an alternate send to address different from what is
saved in the config ie. wicens send /path/email.txt myadd@mail.com
Should Email sending fail the script will retry 4 more times with cron
1/11mins) in 172800 second intervals.
Script generates a lock file /tmp/wicens_lock.tty to prevent
duplicate runs as well as /tmp/wicens_internet_lock.tty
when sending Email notifications. Script will automatically remove stale
lock files if original starting process no longer exists or lock file are
over age limit.
Sendmail/Curl output for Emails is saved to /tmp/wicens_email.log for
debugging if needed. This file can be viewed by running this script and
select option L||l
Sendmail doesnt always return an error code on a misconfiguration so false
send success can occur. If script says Email has sent but no Email received
use option L||l from the Main Menu to read sendmail output for errors
All messages sent to syslog are duplicated in /jffs/addons/wicens/wicens.log
Including failed Email curl logs - Use option z||Z to view wicens.log
The script does not update its saved WAN IP until the script has completed
sending the notification so in the event of message failure it should run
again with next cron run and attempt to send again.
Using option 5 you can call your own script either immediately upon WAN IP
change detection, or wait until the Email message has been successfully sent.
Script will be put in background as to not block this script.
Output from a custom script set to run on WAN IP change is saved to
/jffs/addons/wicens/user_script.log
Hidden menu options
1f - forces build_settings menu
fl - remove mail log file
vv - list out all settings from config files
fr - remove any found update
fe - show example Email text file for using wicens as Email forwarder
ul - show log from user script output when calling script on WAN IP change
rc - reset core config for notification controls, not user config
dwd - disable/enable Dual WAN check
Every Sunday@6pm the script will log the # of times it ran with wan-event.
Thank you for using this script.
SNBforums thread https://www.snbforums.com/threads/wicens-wan-ip-change-email-notification-script.69294/
GitHub source https://github.com/maverickcdn/wicens
This script when configured has the ability to send Email notifications for
Option 2 WAN IP Change (IPv4 only,DualWAN disabled)
Option 5 Script can call your own script when WAN IP change occurs
Option 6 Script Updates (checks every 48hrs when enabled)
Option 7 Firmware Updates (runs with built-in firmware notification check)
Option 8 Router reboot events
Option h shows hidden options
Script can also be used to send your own text generated Email files see
forwarder instructions further below
Supports GMail, Hotmail, Outlook, ISP based Email
Supports AsusWRT-Merlin built-in amtm Email configuration import
Script will function in Double NAT scenarios but does not support Dual WAN
Dual WAN check can be on/off by entering option dwd (default: on)
SMTP Email send formats available:
curl - SSL (eg GMail port 465) # amtm default
sendmail - StartTLS v1.1 higher
sendmail - StartTLS v1 only
sendmail - SMTP plain auth (no encryption)
sendmail - ISP based (no password reqd, generally port 25)
IMPORTANT - If using GMail/Outlook you must use 2 factor authentication and
setup an assigned App password for this script to use.
IMPORTANT - Your Email address(es) are stored as plain text within this
script. Your Email password is encrypted and saved to router storage.
If you dont practice good security habits around your router ssh access,
this script might not be for you.
Script compares IP in nvram for wan0 to saved IP with wan-event connected
events and cron, cron is also a watchdog and monitors for failed Email
attempts. Should the nvram IP be invalid/private IP script will use firmware
built in getrealip.sh to retrieve your WAN IP using Google STUN server.
Router reboot Email contains last known uptime prior to reboot (saved w/cron)
and down time between power loss (last check with cron) and power up time
All cron/wan-event/services-start/update-notification entries needed for this
script are automatically created and removed with enable and disable options.
NTP sync must occur on boot for proper script function
### Technical ###
Supports being used as an Email forwarder for other scripts, in your
script call /jffs/scripts/wicens.sh send {your email.txt path here}
ie. /jffs/scripts/wicens.sh send /tmp/email.txt
Use option fe (unlisted) in the menu to view a sample Email .txt file
When using wicens as an Email forwarder you can pass a second argument after
the Email text path as an alternate send to address different from what is
saved in the config ie. wicens send /path/email.txt myadd@mail.com
Should Email sending fail the script will retry 4 more times with cron
1/11mins) in 172800 second intervals.
Script generates a lock file /tmp/wicens_lock.tty to prevent
duplicate runs as well as /tmp/wicens_internet_lock.tty
when sending Email notifications. Script will automatically remove stale
lock files if original starting process no longer exists or lock file are
over age limit.
Sendmail/Curl output for Emails is saved to /tmp/wicens_email.log for
debugging if needed. This file can be viewed by running this script and
select option L||l
Sendmail doesnt always return an error code on a misconfiguration so false
send success can occur. If script says Email has sent but no Email received
use option L||l from the Main Menu to read sendmail output for errors
All messages sent to syslog are duplicated in /jffs/addons/wicens/wicens.log
Including failed Email curl logs - Use option z||Z to view wicens.log
The script does not update its saved WAN IP until the script has completed
sending the notification so in the event of message failure it should run
again with next cron run and attempt to send again.
Using option 5 you can call your own script either immediately upon WAN IP
change detection, or wait until the Email message has been successfully sent.
Script will be put in background as to not block this script.
Output from a custom script set to run on WAN IP change is saved to
/jffs/addons/wicens/user_script.log
Hidden menu options
1f - forces build_settings menu
fl - remove mail log file
vv - list out all settings from config files
fr - remove any found update
fe - show example Email text file for using wicens as Email forwarder
ul - show log from user script output when calling script on WAN IP change
rc - reset core config for notification controls, not user config
dwd - disable/enable Dual WAN check
Every Sunday@6pm the script will log the # of times it ran with wan-event.
Thank you for using this script.
SNBforums thread https://www.snbforums.com/threads/wicens-wan-ip-change-email-notification-script.69294/
GitHub source https://github.com/maverickcdn/wicens
Version 4 brings another re-write of the script, additions, and overall optimizations
v4.00 has limited testing so please advise of issues and I will look to resolve as time allows
Script requires being configured with your To/From Email address(es), server address/port etc. or can sync with your amtm Email config
Firmware must be 384.15 or newer, or on Johns fork 374.43_48D3j9527 or newer
To install, scripts/ssh must be enabled. Install from amtm main menu or from an SSH terminal, copy/paste
Code:
curl --retry 3 "https://raw.githubusercontent.com/maverickcdn/wicens/master/wicens.sh" -o "/jffs/scripts/wicens.sh" && chmod a+rx "/jffs/scripts/wicens.sh"
For first run, use the following to access the Menu.
Code:
sh /jffs/scripts/wicens.sh
After first run and starting a new terminal session, you should be able to access the menu by simply entering
Code:
wicens
Use option b to create a backup of your configured settings if ever formatting /jffs or reinstalling wicens. Saved to script directory /jffs/addons/wicens (*uninstall removes backups you must manually copy to a safe location)
In SMTP server send config type, option 4 (SMTP Plain auth) is still untested. Support for sendmail options is depreciated.
Hope people can find this script useful, and would welcome your feedback, there's already 3 user requested custom fields. I find scripting a nice escape from everyday life.


To truly test the script (built in test only tests Email function), use nano to edit the saved_wan_ip to something different (not blank) in /jffs/addons/wicens/wicens_user_config.wic and let it run with cron (default 11mins). Those taking advantage of the custom script calling function should certainly test it this way.
Feeling generous?
Last edited: