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
  • Seems like a lot of work for what could be done with a simple shell script.

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

    :edited to change adapter info (eth0->ppp0)

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

  • For ollion : yep ... but like i said ... it's only if u haven't got a DDNS ... thanks for ur links ... for information the ddclient is very ease to use ...

    For Jef Brownlee : yep ... and i didn't say that i'm a great programer too ... and i don't find the sendmail bin ... so i must use perl ... More over ... the perl script send the IP only if this one change ... not urs

    For Resistance : do that as root :
    *** create a file /etc/crontab.ip
    > touch /etc/crontab.ip
    *** put the line in the file 
    > echo '.... the line ... ' >> /etc/crontab.ip
    *** verify the line 
    > cat /etc/crontab.ip
    *** reboot the firewall

    In fact the file /etc/crontab is automaticaly done by the system from crontab.* files ;-)

    Good Hack

    And thanks for ur posts
  • I agree on the annoyance of being emailed constantly if the IP hasn't changed...here is the tweak to track the ip changes.  

    CIP=`/sbin/ifconfig eth0 | 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
  • You can just create the file crontab.ip in the /etc directory with the script above (second one if you only want email when the ip actually changes).  The 0 * * * * root  in the crontab.ip is actually a directive explaining when it is to be run and by whom.  To activate this file, reboot once it is created, and it will be automatically inserted into the runtime crontab file.
  • Thanks Jeff ... better solution now ...   [;)]
  • 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?
  • 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
Reply
  • 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
Children
No Data
Share Feedback
×

Submitted a Tech Support Case lately from the Support Portal?