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 ]

  • I really want this little hack but I am kinda noob.  The script by Jeff Brownlee makes sence and seems easy.    I dont have a .ip file so do I make a new file?   And if yes do I have to auto start the script somewhere or is this all the code I need?

    Thanks in advance
    Resistance
  • 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.
Reply
  • 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.
Children
Share Feedback
×

Submitted a Tech Support Case lately from the Support Portal?