Skip to content

Instantly share code, notes, and snippets.

@cherts
Last active August 11, 2021 10:13
Show Gist options
  • Select an option

  • Save cherts/beb8cfe7b84859dc63dd3817c2eb135d to your computer and use it in GitHub Desktop.

Select an option

Save cherts/beb8cfe7b84859dc63dd3817c2eb135d to your computer and use it in GitHub Desktop.
Check domain expires days
#!/usr/bin/env bash
#
# Program: Check domain expires days <whois_domain_expire.sh>
#
# Author: Mikhail Grigorev <sleuthhound at gmail dot com>
#
# Current Version: 1.0.2
#
# License:
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
URL=$1
_usage() {
echo ""
echo "Usage: $0 domain.com"
echo ""
exit 1
}
[ $# -eq 0 ] && _usage
nslookup "${URL}" >/dev/null 2>&1
if [ $? -eq 0 ]; then
TODAY=$(date '+%Y-%m-%d')
DOMAIN=$(whois "${URL}" 2>/dev/null | egrep -i "Expires.*:|Expiration.*:|Renewal.*:|expir.*date:|paid-till:" | head -n 1 | cut -d: -f2- | sed -e's/^[ ]*//' | sed 's/^[ \t]*//;s/[ ]*$//')
DOMAIN_EXPIRES=$(( ($(date -d "${DOMAIN}" "+%s" 2>/dev/null) - $(date -d "${TODAY}" "+%s" 2>/dev/null) ) / 86400 ))
if ! [[ "${DOMAIN_EXPIRES}" =~ ^[0-9]+$ ]]; then
DOMAIN_EXPIRES=0
fi
if [ -n "${DOMAIN_EXPIRES}" ]; then
echo -n "${DOMAIN_EXPIRES}"
else
echo -n "0"
fi
else
echo -n "0"
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment