forked from PeterDaveHello/nrd-list-downloader
-
Notifications
You must be signed in to change notification settings - Fork 2
/
nrd-list-downloader.sh
executable file
·130 lines (102 loc) · 4.25 KB
/
nrd-list-downloader.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env bash
# nrd-list-downloader
# https://github.com/PeterDaveHello/nrd-list-downloader
# Copyright (C) 2022 ~ Peter Dave Hello
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# 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. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# ColorEchoForShell #
# https://github.com/PeterDaveHello/ColorEchoForShell
# Copyright (C) 2015 ~ Peter Dave Hello
function echo.Red() {
echo -e "\\033[31m$*\\033[m"
}
function echo.Green() {
echo -e "\\033[32m$*\\033[m"
}
function echo.Cyan() {
echo -e "\\033[36m$*\\033[m"
}
# ColorEchoForShell End #
function error() {
echo.Red >&2 "$@"
exit 1
}
for cmd in mkdir wc base64 curl cat zcat mktemp date tr realpath dirname; do
if ! command -v "$cmd" > /dev/null 2>&1; then
error "command: $cmd not found!"
fi
done
set -e
DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
DAY_RANGE="${DAY_RANGE:-7}"
DAILY_DIR="${DAILY_DIR:-daily}"
TEMP_FILE="$(mktemp -p "$DIR" --suffix=nrd)"
PAID_WHOISDS_USERNAME="${PAID_WHOISDS_USERNAME:-}"
PAID_WHOISDS_PASSWORD="${PAID_WHOISDS_PASSWORD:-}"
BASE_URL_FREE="https://whoisds.com/whois-database/newly-registered-domains"
BASE_URL_PAID="https://whoisds.com/your-download/direct-download_file/${PAID_WHOISDS_USERNAME}/${PAID_WHOISDS_PASSWORD}"
COMMENT="# NRD list generated by nrd-list-downloader, on $(date '+%Y-%m-%d'), data source: WhoisDS.com"
cd "$DIR"
echo.Green "You are using nrd-list-downloader to download NRD(Newly Registered Domain) list ..."
echo.Cyan "NRD list of the last $DAY_RANGE days will be downloaded."
function insert_into_temp_file() { echo "$*" >> "$TEMP_FILE"; }
insert_into_temp_file "$COMMENT"
function download() {
local TYPE="${1:-free}"
local TARGET_FILE="nrd-${DAY_RANGE}days-${TYPE}.txt"
local DOWNLOAD_DIR="${DAILY_DIR}/${TYPE}"
mkdir -p "$DOWNLOAD_DIR"
echo
echo.Cyan "Downloading $TYPE NRD list ..."
if [ "free" = "$TYPE" ] && [ "$DAY_RANGE" -gt "10" ]; then
echo.Red "Warning! Free NRD list before more than 10 days might be removed from WhoisDS.com already, the download may failed."
fi
if [ "paid" = "$TYPE" ] && [ "$DAY_RANGE" -gt "30" ]; then
echo.Red "Warning! Paid NRD list before more than 30 days might be removed from WhoisDS.com already, the download may failed."
fi
local i="$DAY_RANGE"
while [ "$i" -gt "0" ]; do
local DATE FILE URL FREE_URL_INFIX
DATE="$(date -u --date "$i days ago" '+%Y-%m-%d')"
FILE="${DOWNLOAD_DIR}/${DATE}"
if [ -s "$FILE" ] && [ "$(grep -vc '^$' "$FILE")" -ge "1" ] ; then
echo.Cyan "$FILE existed with $(grep -vc '^$' "$FILE") domains, skip the download and decompress process ..."
else
printf "%s" "Download and decompress $DATE data ... "
if [ "paid" = "$TYPE" ]; then
URL="${BASE_URL_PAID}/${DATE}.zip/ddu"
else
FREE_URL_INFIX="$(echo "${DATE}.zip" | base64)"
URL="${BASE_URL_FREE}/${FREE_URL_INFIX:0:-1}/nrd"
fi
curl -sSLo- "$URL" | zcat | tr -d '\015' >> "$FILE"
echo "" >> "$FILE"
echo.Cyan "$(grep -vc '^$' "$FILE") domains found."
fi
insert_into_temp_file "# ${DATE} NRD start"
cat "$FILE" >> "$TEMP_FILE"
insert_into_temp_file "# ${DATE} NRD end"
i="$((i - 1))"
done
insert_into_temp_file "$COMMENT"
chmod +r "$TEMP_FILE"
mv "$TEMP_FILE" "$TARGET_FILE"
echo.Green "NRD list for the last $DAY_RANGE days saved to $TARGET_FILE, $(grep -cvE '^(#|$)' "$TARGET_FILE") domains found."
echo
}
download free
if [ -n "$PAID_WHOISDS_USERNAME" ] && [ -n "$PAID_WHOISDS_PASSWORD" ]; then
echo.Green "WhoisDS paid account found! Will try to download paid premium NRD package with it."
download paid
fi