Last active
August 11, 2021 10:13
-
-
Save cherts/beb8cfe7b84859dc63dd3817c2eb135d to your computer and use it in GitHub Desktop.
Check domain expires days
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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