WAN IPCheck - Send an email if WAN IP has changed

Post new topic   Reply to topic    DD-WRT Forum Index -> Contributions Upload
Goto page 1, 2, 3, 4  Next
Author Message
cyberde
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 1488
Location: the Netherlands

PostPosted: Fri Jun 01, 2007 9:54    Post subject: WAN IPCheck - Send an email if WAN IP has changed Reply with quote
Hi, after getting a request to write a script to check your WAN ip for changes (here), and email the new ip-address to you if changed. I decided to create that script, because it seemed handy.


The attached zipfile includes the folowing:
- wanipcheck.sh
- sendmail (used for sending the notification email, I didn't made that)

Howto use this script?
Well it's easy, all you have to do is enter the variables:
Code:
INTERVAL=3600
MAIL_BINARY=/mmc/usr/sbin/sendmail
MAIL_SERVER=smtp.isp.com
MAIL_TO=emailto@isp.com
MAIL_FROM=emailfrom@isp.com
MAIL_SUBJECT="Some subject for your email"


To be able to use it, you should have an SDcard mod or JFFS2 space left to save this script and save the sendmail binary. A samba share should do too.
To start the script automatically on router boot, you could enter ./wanipcheck.sh & to your startup script or save it as eg. /mmc/etc/config/wanipcheck.startup.
For more info on this have a look at Startup scripts in the Wiki.


How does it work?
Also easy, it creates an nvram variable with the old ip-adrress and compares it to the nvram variable wan_ipaddr (which contains the current ip). If changed it sends an email (if enabled ofcourse).

The email looks like this:
Code:
WAN IP Address has changed to: 12.34.56.78
Previous known IP Address: 54.32.234.241


I hope this little script might come in handy for someone :)

P.S. If you have any additions or improvements, please post them :)


Other script:
PortCheck emails you when a connection has been made to a specific port.

_________________
Firmware: DD-WRT v24-sp2 (latest available) mega
WRT320N

Donater
Sponsor
bruns
DD-WRT Novice


Joined: 07 Jun 2006
Posts: 22
Location: NYC

PostPosted: Thu Jun 21, 2007 20:56    Post subject: Reply with quote
For those who need it, I have a build of msmtp for dd-wrt available here in case you don't have an external mmc card and need something tiny (under 100kb) to fit on the existing empty jffs space.:

http://users.sosdg.org/~bruns/dd-wrt/msmtp-1.4.12cvs-ddwrt.tar.bz2

Unpack this, put the contents of bin/ in /jffs/bin, contents of etc/ in /jffs/etc. Edit /jffs/etc/msmtprc.

ln -s /jffs/bin/msmtp /jffs/bin/sendmail

Adjust your programs as necessary, and they will use msmtp as if its sendmail.

_________________
Brielle Bruns
The Summit Open Source Development Group
http://www.sosdg.org
cyberde
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 1488
Location: the Netherlands

PostPosted: Fri Jun 22, 2007 7:58    Post subject: Reply with quote
nice, but sendmail is just 12 kb Wink
_________________
Firmware: DD-WRT v24-sp2 (latest available) mega
WRT320N

Donater
bruns
DD-WRT Novice


Joined: 07 Jun 2006
Posts: 22
Location: NYC

PostPosted: Fri Jun 22, 2007 13:10    Post subject: Reply with quote
Maybe I missed something, but how could sendmail be that small on DD-WRT when its a pretty heavyweight binary on all other platforms... Unless, its a stub only. Heh, oh well. msmtp still does well.
_________________
Brielle Bruns
The Summit Open Source Development Group
http://www.sosdg.org
cyberde
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 1488
Location: the Netherlands

PostPosted: Fri Jun 22, 2007 13:32    Post subject: Reply with quote
Have no idea, but it does work like a charm (I already included it in the ZIP).
_________________
Firmware: DD-WRT v24-sp2 (latest available) mega
WRT320N

Donater
alessy
DD-WRT Novice


Joined: 17 Sep 2007
Posts: 4

PostPosted: Tue Sep 18, 2007 5:21    Post subject: Reply with quote
Hello everybody.
I must tell, that I'm not an expert like you are so i beg for help.
Actualy I realy need some help, how to get this script into the router and how make it work.

With help of startup scripts I used script in wanipcheck.sh file and I put it in the command window in router settings. I have save it and try it. But it doesent work.

I've changed this settings

INTERVAL=3600
MAIL_BINARY=/mmc/usr/sbin/sendmail
MAIL_SERVER=smtp.isp.com
MAIL_TO=emailto@isp.com
MAIL_FROM=emailfrom@isp.com
MAIL_SUBJECT="Some subject for your email"

and i tried some things, but it doesent work for me. I have missed something, or I'm doing all wrong. So please help me. I need some basic instructions for dummies.

I have router BUFFALO WHR-HP-G54
with DD-WRT v23 sp2
cyberde
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 1488
Location: the Netherlands

PostPosted: Wed Sep 19, 2007 10:47    Post subject: Reply with quote
Do you have storage to save the script and the sendmail binary? Eg jffs? If not it's highly unlikely it's gonna work cause you need the sendmail binary in order to send the emails.

Something you can try is create this script using the startup script and make it download the sendmail binary from a remote website. Even better, samba/cif Smile

_________________
Firmware: DD-WRT v24-sp2 (latest available) mega
WRT320N

Donater
gneville
DD-WRT Novice


Joined: 16 May 2008
Posts: 1

PostPosted: Fri May 16, 2008 20:44    Post subject: Re: WAN IPCheck - Send an email if WAN IP has changed Reply with quote
Nice One.

Thanks
Daddyfix
DD-WRT User


Joined: 10 Jul 2008
Posts: 57

PostPosted: Thu Jul 10, 2008 14:53    Post subject: THANKS Reply with quote
Thank you. This really helps me with my dynamic IP address.
cyberde
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 1488
Location: the Netherlands

PostPosted: Thu Jul 10, 2008 15:16    Post subject: Reply with quote
No problem, glad I could do something back for the community Smile
_________________
Firmware: DD-WRT v24-sp2 (latest available) mega
WRT320N

Donater
switch
DD-WRT Guru


Joined: 30 Apr 2008
Posts: 967
Location: Romania

PostPosted: Fri Jul 11, 2008 8:23    Post subject: Reply with quote
I guess this could be useful if you want to know when you Dynamic Host(DynDNS.org, anyone?) changes without relying on their logs.
_________________
Q: How do I do ...? A: Read the tutorials or Search forums
cyberde
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 1488
Location: the Netherlands

PostPosted: Fri Jul 11, 2008 16:24    Post subject: Reply with quote
Exactly, but also if you manage your own DNS for your own domain. For example MX records.
_________________
Firmware: DD-WRT v24-sp2 (latest available) mega
WRT320N

Donater
tawny
DD-WRT Novice


Joined: 13 Aug 2008
Posts: 1

PostPosted: Thu Aug 21, 2008 14:33    Post subject: Re: WAN IPCheck - Send an email if WAN IP has changed Reply with quote
Just got my Linksys last week and came across this thread when searching for a means to email from the router. Big thanks to cyberde.

A few thoughts for others who might be using this technique:


    I have commented-out the commit statements in wanipcheck.sh to reduce writes to /jffs

    As bruns, queried above, sendmail isn't THE sendmail but rather mini_sendmail http://www.acme.com/software/mini_sendmail/, msmtp is more comprehensive in its capabilities and has much more documentation. Thanks to bruns too.

    I tested sendmail with three external ISP mailservers and they all flagged the messages as possible spam because of missing headers which didn't happen when using msmtp.


Thanks guys!
phlex
DD-WRT Novice


Joined: 23 Aug 2008
Posts: 5

PostPosted: Sat Aug 23, 2008 11:00    Post subject: things Reply with quote
hello

i need help in two ways..
where can i find the zip-file?
why i can´t type two script in the command window, not in one but like this: 24disconned pland and sendmail in two steps?

thx
phlex
DD-WRT Novice


Joined: 23 Aug 2008
Posts: 5

PostPosted: Sat Aug 23, 2008 11:01    Post subject: things 2 Reply with quote
so sorry.. just signup.. and see the file 8((
Goto page 1, 2, 3, 4  Next Display posts from previous:    Page 1 of 4
Post new topic   Reply to topic    DD-WRT Forum Index -> Contributions Upload 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 cannot attach files in this forum
You cannot download files in this forum