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?
 
Back
Top Bottom