Linux box emails new Dynamic ADSL IP script

midafricam

New Member
Joined
Feb 27, 2004
Messages
4
Reaction score
0
Location
.
Install the Lynx software package and insert as scheduled job in your /etc/crontab file ie 0 8 * * 1-5 root adslscript.sh
So every morning Mon to Fri at 8am the new IP address is emailed to you
Script care of Louis Reynecke who hacked it somewhere

#!/bin/bash

# A script file to get my current ip address
lynx -source http://checkip.dyndns.org | awk -F : '{print($2)}'| awk -F \< '{print($1)}'| mail -s "New ADSL Dynamic IP address" [email protected]

Setup your ADSL Router under Basic Config -> PAT
TCP ATM1 SSH port 22 IP address of Linux box Port 22

Now you can SSH into the external IP of your Linux box
if you have installed 2 network cards.

Cheers
Justin Miles
 
I've tried using the above command, but when it returns my IP address there's a 'space' character leading my IP address - and this is interfering with my dynamic DNS.

Is there a way to get rid of that space character?

lynx -source http://checkip.dyndns.org | awk -F : '{print($2)}'| awk -F \< '{print($1)}'

That above command will retrieve your IP address by checking it against DynDNS. It will remove all other text surrounding the IP address, but it doesn't remove the single space character leading the output results.

Please help!
 
Hold on guys... I found something:

awk '{sub(/^[ \t]+/, ""); print}'

That will remove any spaces before my string - which is good! It works and I've tested it via the command prompt.

However, my dynamic DNS script is written in PHP so I get an error when I try issue this command in my PHP scipt:

lynx -source http://checkip.dyndns.org/ | awk -F : '{print($2)}' | awk -F \< '{print($1)}' | awk '{sub(/^[ \t]+/, ""); print}'

Any ideas?

Is there a way to re-write the above line so that it doesn't return an error within a PHP file?

Thanks...
 
i use a dns server on a fixed ip running bind 9 and simply fire a nsupdate to it ...

now im setup what i can now do is host other stub zones on my link for others ... i use nsupdate in cron and ip-up

file generated by ip-up
-----
server <SERVER ADDIE>
zone smartdns.co.za
key smartdns.co.za <MIME64 KEY>
update delete netsentry.smartdns.co.za. A
update add netsentry.smartdns.co.za. 180 A <IP ADDRESS>
send
-----

snipit from ip-up
----------
FWD_DNS=`echo $4 |awk -F. '{print "dig "$4"."$3"."$2"."$1".in-addr.arpa PTR +short"}' |sh |head -1`
REV_DNS=`dig $FWD_DNS A +short |tail -1`

EMAIL_SERV=`echo $FWD_DNS |awk '{print substr($0,0,length($0)-1)}'`

if [ "$REV_DNS" != "$4" ];then
ADD_DNS="update add firewall 180 A $4"
cp /etc/mail/sendmail.cf.orig /etc/mail/sendmail.cf
EMAIL_PID=`pidof sendmail`
if [ "$EMAIL_PID" ];then
kill -1 `cat /var/run/sendmail.pid |head -1`
else
/etc/rc.d/rc.mail
fi;
else
ADD_DNS="update add firewall 180 CNAME $FWD_DNS"
sed -e "s/^Dj.*/Dj$EMAIL_SERV/" /etc/mail/sendmail.cf.orig > /etc/mail/sendmail.cf
EMAIL_PID=`pidof sendmail`
if [ "$EMAIL_PID" ];then
kill -1 `cat /var/run/sendmail.pid |head -1`
else
/etc/rc.d/rc.mail
fi;
fi;
------------
 
Shocking!

Just use ddclient people.

- Colin Alston
colin at alston dot za dot org

"Getting traffic shaping right is easy and can be summed up in one word: Dont." -- George Barnett
 
Top
Sign up to the MyBroadband newsletter
X