Guest User!

You are not Sophos Staff.

A little hack for ASL ... 3.51

Hello everyone,
Listed below a little perl script witch automaticaly mail the public IP of a PPP connection managed by the firewall. It's very usefull if u don't have a static public IP or a dynamic DNS ...

after only add a line in the crontab like this :
0 * * * * root /bin/perl /bin/mail_ip.pl

>>>>>>>>> Snip Snip : /bin/mail_ip.pl " ;="" my="" $mail_srv="" ;="" my="" @mail_det="qw" (="" adress_mail_user_1="" adress_mail_user_2="" ...="" )="" ;="" #="" #="" get="" actual="" ip="" #="" my="" $cmd="ifconfig ppp0 | grep inet | awk '{print \$2}' | sed 's/^addr://g'" ;="" my="" @tmp="`$cmd`" ;="" foreach="" (="" @tmp="" )="" {="" chomp="" ;="" s/^\s//;="" s/\s+$//;="" }="" my="" $addr="@tmp[0]" ;="" #="" #="" get="" last="" ip="" found="" during="" last="" execution="" of="" this="" script="" #="" $cmd="cat /tmp/wan_addr_flag" ;="" @tmp="`$cmd`" ;="" foreach="" (="" @tmp="" )="" {="" chomp="" ;="" s/^\s//;="" s/\s+$//;="" }="" my="" $addr_old="@tmp[0]" ;="" #="" #="" send="" mail="" and="" memorise="" last="" adresse="" if="" both="" are="" different="" #="" if="" (="" $addr="" ne="" $addr_old="" )="" {="" print="" "send="" mail="" ...\n"="" ;="" foreach="" my="" $mail_dest="" (="" @mail_det="" )="" {="" my="" $mail="Net::SMTP-">new($mail_srv) ;
$mail->mail($mail_src) ;
$mail->to($mail_dest);
$mail->data() ;
$mail->datasend("To:".$mail_dest."\n") ;
$mail->datasend("From:".$mail_src."\n") ;
$mail->datasend("Subject: Adresse IP\n") ;
$mail->datasend("\n") ;
$mail->datasend($addr."\n") ;
$mail->dataend() ;
$mail->quit() ;
}
$cmd = "echo ".$addr." > /tmp/wan_addr_flag" ;
`$cmd` ;
}
exit 0 ;

>>>>>>>>>>>>>>>>>>> The end 
Parents Reply
  • Hey guys I tryped in exactly what you have into etc/crontab.ip and I dont get anything via email?  

    I do get all alerts from my firewall restarting.  I do see the script in /etc/crontab after reboot?  Am I just missing something?   Jeffs first script?   Should I try his 2nd script?  Should I delete the 1st script or is your 2nd script an add on Jeff?
Children
  • your crontab.ip should look like this:

    0 * * * * root CIP=`/sbin/ifconfig ppp0 | grep inet | awk '{print $2}' | sed 's/^addr://g'`;LIP=`cat /tmp/lastip`;if test "$CIP" != "$LIP"; then echo $CIP>/tmp/lastip; for addr in `cat /etc/adminmail`; do echo -e "To: $addr\nFrom: notify@`cat /etc/hostname`\nSubject:IP Address Change\nNew IP: $CIP\n\n." | /var/qmail/bin/sendmail -t; done; fi 

    Note this is all on one line and has no CRs.  Once this is in, reboot and make sure there is a single line for it in /etc/crontab.  At the top of the hour, there should be a file in /tmp called lastip, and you should receive an email (since it was not there to begin with).


    ADDED: I tried to reproduce your problem, but didn't have any system events flowing through.  Running /var/qmail/bin/qmail-qstat showed all messages backlogged (53 i believe).  Started and stopped the SMTP proxy (from web interface) and all messages started flowing through (even after disabling).

    [ 09 May 2002: Message edited by: Jeff Brownlee ]

  • Also, what version of ASL are you running?  Was just playing with a friend's beta version and noticed qmail has been replaced with exim, which will complicate the process a bit (sendmail is no longer in /var/qmail/bin/sendmail)
  • [duplicate deleted]

    [ 13 May 2002: Message edited by: Jeff Brownlee ]

  • Sorry it took so long to get back to you on this, found the change from qmail to exim and wanted a more version independant method of sending the notification.  This should work on any current/beta version (again, all on one line):

    crontab.ip
    0 * * * * root CIP=`/sbin/ifconfig ppp0 | grep inet | awk '{print $2}' | sed 's/^addr://g'`;LIP=`cat /tmp/lastip`;if test "$CIP" != "$LIP"; then echo $CIP>/tmp/lastip; for addr in `cat /etc/adminmail`; do /usr/local/bin/anotifier "IP Address Change" /tmp/lastip $addr; done; fi
Share Feedback
×

Submitted a Tech Support Case lately from the Support Portal?