Track dynmic IP remotely

Soldato
Joined
15 Feb 2003
Posts
10,139
Location
Europe
Carrying on from this thead: http://forums.overclockers.co.uk/showthread.php?t=18380256

I'd rather have my own custom solution and thought it's better to post here instead.

I want to create a script to run at startup on my debian system to do the following:

1) Check the current public ip address by wget http://automation.whatismyip.com/n09230945.asp

2) record this ip to a file and into an external mysql databse

3) check this ip against the record, if changed then fire off an email

I'm planning to use this script as the basis:
Code:
 #!/bin/sh
# Connects to www.whatismyip.com every 12 hours to get IP address and checks if it has changed

clear
output_filename="/home/<myusername>/ip_history.txt"
while [ 1 ]
  do IPADR2=$IPADR;
  IPADR=$(wget http://automation.whatismyip.com/n09230945.asp -O - -q)
  dttim=$(date -j +"%d %b %Y @ %H:%M:%S")
  if [ "$IPADR" != "$IPADR2" ]; then
    echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> $output_filename
    echo ~~~~~ IP Address has changed ... $dttim >> $output_filename
    echo ~~~~~ Our Old IP Address was -- $IPADR2 >> $output_filename
    echo ~~~~~ Our New IP Address is --- $IPADR >> $output_filename
    echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> $output_filename

    mail -s "IP Changed" [email protected] << E_O_M
Good day Master,

  Your IP Has Changed

  Your Old IP Address was -- $IPADR2
  Your New IP Address is --- $IPADR

  This Occurred Within The Past 12 Hours From -- $dttim

  
  Reference: $output_filename
E_O_M

  else
    echo IP Address is the same ... as of $dttim ... $IPADR  >> $output_filename
  fi
  sleep 43200 # 12h = 43200
done

Any ideas on going about this?
 
Hi!

I tried something similar a few weeks ago to track my IP, enabling me to get to my Apple TV. However, my ATV didn't have sendmail. The script below might help...


#!/bin/sh

MYIP=`awk '{print $1}' MYIP.log
i = 1

while $i
do
CURRENTIP=`wget -O - -q icanhazip.com`
if [ "$CURRENTIP" != "$MYIP" ]
then
echo "## ## ## ## ## ## ## ## #"
echo "## IP Changed ##"
echo "## ## ## ## ## ## ## ## #"
else

wget -O - -q icanhazip.com > /home/user/MYIP.log
mail -s “New IP” [email protected] < /home/user/MYIP.log
exit

done


I'm waiting until I get my Raspberry Pi, but let me know if it works.

/MW
 
Back
Top Bottom