
#!/bin/sh
# File	: chk_ip-adress-and-domain.sh
# By	:  MaartenDeBoer.nl, 161231
# Subject	: Script to get IP-address from chageip-com and check domainname
# Based on : http://www.changeip.com/accounts/dl.php?type=d&id=2
#set -x
#(0.2)	: Mod DNSIP
#(0.3)	: Add ETC-file
#(0.4),171209	: Added nslookup when OWNDNS=""
#(0.5),171214	: Added 2x nslookup
PGM="`basename $0|cut -d\. -f1`"
VER="0.5"
TMP="/tmp/${PGM}.$$"
# Using ETC
DOMAINNAME="www.agrarix.net"
MAILTO="maarten@agrarix.nl"
ETC="${HOME}/etc/${PGM}"

if [ -f ${ETC} ]; then
  DOMAINNAME="`cat ${ETC}|grep -v ^#|grep DOMAINNAME|awk -F\= '{print $2}'`"
  echo "New DOMAINNAME=${DOMAINNAME}"
fi  # ETC

wget -q -U "${PGM} ${VER}" -O ${TMP} ip.changeip.com
OWNIP="`cat ${TMP}|grep -v IP|grep [1..0]`"
DNSIP="`dig +short ${DOMAINNAME}|grep [0-9]|head -1`"
if [ "${OWNIP}" = "" ]; then
  OWNIP=`/usr/bin/nslookup ${DOMAINNAME}|grep -v \#|grep Address|cut -d\: -f2|sed 's/ //g'`
fi
if [ "${OWNIP}" = "" ]; then
  OWNIP=`/usr/bin/nslookup ${DOMAINNAME}|grep -v \#|grep Address|cut -d\: -f2|sed 's/ //g'`
fi
if [ "${OWNIP}" = "" ]; then
  OWNIP=`/usr/bin/nslookup ${DOMAINNAME}|grep -v \#|grep Address|cut -d\: -f2|sed 's/ //g'`
fi

if [ "${OWNIP}" != "${DNSIP}" ]; then
  echo "OWNIP(${OWNIP}) <> DNSIP(${DNSIP}) of ${DOMAINNAME}"
  echo "Own IP-address (${OWNIP}) NOT equal as DNS IP-address (${DNSIP}) for domain ${DOMAINNAME}"|mailx -s "[${PGM} v${VER}]" ${MAILTO}
else
  echo "OWNIP(${OWNIP}) = DNSIP(${DNSIP}) of ${DOMAINNAME}"
fi

rm ${TMP}
exit 0

