Skip to content

Instantly share code, notes, and snippets.

@rogersguedes
Created October 19, 2020 01:03
Show Gist options
  • Save rogersguedes/e2a19d27849bd22b8fcd1ec6ff083a7a to your computer and use it in GitHub Desktop.
Save rogersguedes/e2a19d27849bd22b8fcd1ec6ff083a7a to your computer and use it in GitHub Desktop.
#/bin/bash
source ${HOME}/.bashrc_rogers
LOGFILE_NAME=whatismyip.log
GATEWAY_IP=192.168.0.1
IP_PAGE_URL=checkip.dyndns.org
LAST_IP=`whatismyip`
echo "Initial IP: ${LAST_IP}"
while true
do
sleep 2
CURR_TIME=`discendingDateAndTime`
echo "."
CURR_IP_HTML=`curl -s ${IP_PAGE_URL}`
if [ $? -ne 0 ]; then
echo "[${CURR_TIME}] Couldn't connect to ${IP_PAGE_URL}" >> ${LOGFILE_NAME}
GT_PING_STDOUT=`ping -c 1 ${GATEWAY_IP} 2>/dev/null`
if [ $? -ne 0 ]; then
echo "[${CURR_TIME}] Couldn't reach LAN Gateway (${GATEWAY_IP})" >> ${LOGFILE_NAME}
fi
continue
fi
CURR_IP=`echo ${CURR_IP_HTML}| sed -e 's/.*Current IP Address: //' -e 's/<.*$//'`
if [ ${CURR_IP} != ${LAST_IP} ]; then
echo "[${CURR_TIME}] IP changed, ${LAST_IP} => ${CURR_IP}" >> ${LOGFILE_NAME}
fi
LAST_IP=${CURR_IP}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment