Joined: 07 Jun 2006 Posts: 1488 Location: the Netherlands
Posted: Thu Jan 25, 2007 21:06 Post subject: PortCheck - Send an email if a connection has been made
Hi, I was looking for a way to get an email if a connection has been made to a specific port (eg my OpenVPN). But I didn't find any, so I decided to create one my own.
The attached zipfile includes the folowing:
- portcheck.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=5
PORT=443
CHECK_ONLY_WAN=1
LOGFILE=/tmp/somelogfile.log
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"
MAIL_ON_CONNECT=1
MAIL_ON_DISCONNECT=1
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 ./portcheck.sh & to your startup script or save it as eg. /mmc/etc/config/portcheck.startup.
For more info on this have a look at Startup scripts in the Wiki.
How does it work?
Also easy, it counts the current connections to the specified port from "netstat -n". If the amount changed with the previous value it adds some info to the specified logfile and then emails it (if enabled ofcourse).
The logfile looks like this:
Code:
Thu Jan 25 21:51:47 UTC 2007 Log started
Thu Jan 25 21:51:52 UTC 2007 1 established connection(s)
Thu Jan 25 21:51:52 UTC 2007 Clients: 62.140.X.X
Thu Jan 25 21:52:44 UTC 2007 0 established connection(s)
I hope this little script might come in handy for someone :)
P.S. If you have any additions or improvements, please post them _________________ Firmware: DD-WRT v24-sp2 (latest available) mega
WRT320N
Joined: 07 Jun 2006 Posts: 1488 Location: the Netherlands
Posted: Tue Jan 30, 2007 19:16 Post subject:
You can, but to do that you need to run this script twice with other settings...
Eg.
vpncheck.sh
port123check.sh
So it's not possible to do that with just one script... Maybe that's something for the next version _________________ Firmware: DD-WRT v24-sp2 (latest available) mega
WRT320N
Thanks im gona check this out later. Could you update it for mailserver auth or post the sendmail docs ...I looked and could not find one on what arguments are what
Great topic! I'm trying to do something similar. I have a dynamic IP address from my wan and can't change it to static. So I would like to send an email every time the wan IP address changes. Does someone know how to do this?
Joined: 07 Jun 2006 Posts: 1488 Location: the Netherlands
Posted: Thu May 24, 2007 13:43 Post subject:
Sure, you can write the output `nvram get wan_ipaddr` to a file on jffs / mmc or even create your own nvram variable for it.
After that you can compare the both values eg of wan_ipaddr and wan_ipaddr_before and if changed send an email. _________________ Firmware: DD-WRT v24-sp2 (latest available) mega
WRT320N
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.:
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
Posted: Sat Aug 30, 2008 15:51 Post subject: Status mail
Hey,
is it possible to send a mail every 15 minutes to a special email account with a special subject so that I can see if my AP is online without open ports?
And furthermore is it possible to receive emails, so that if there is a email in a pop3 inbox a vpn connection is establihed, because I don't wanna open ports.
Or do you see any other possibility to connect to the router without port forwarding?