-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathmain-domains-resolver.sh
executable file
·141 lines (124 loc) · 4.14 KB
/
main-domains-resolver.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
131
132
133
134
135
136
137
138
139
140
141
#!/bin/bash
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
MAGENTA='\033[0;35m'
CYAN='\033[0;36m'
BOLD='\033[1m'
NC='\033[0m'
line_skip() { echo -e ". . ."; }
log_info() { echo -e "${CYAN}[INFO]${NC} $*"; }
log_success() { echo -e "${GREEN}[OK]${NC} $*"; }
log_warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
log_error() { echo -e "${RED}[ERROR]${NC} $*"; }
BASE_DIR="$(cd "$(dirname "$0")" && pwd)/main_domains"
DOMAIN_LIST_FILE="$BASE_DIR/discord-main-domains-list"
IP_LIST_FILE="$BASE_DIR/discord-main-ip-list"
JSON_OUTPUT_FILE="$(cd "$(dirname "$0")" && pwd)/amnezia/amnezia-discord-domains.json"
PROGRESS_BAR_LENGTH=50
mkdir -p "$BASE_DIR"
mkdir -p "$(dirname "$JSON_OUTPUT_FILE")"
log_info "Очистка устаревших списков..."
: > "$IP_LIST_FILE"
: > "$JSON_OUTPUT_FILE"
echo "[" > "$JSON_OUTPUT_FILE"
first_entry=true
if pgrep dnsmasq > /dev/null 2>&1; then
log_info "Перезапускаем dnsmasq..."
pkill -SIGHUP dnsmasq
else
log_warn "А куда же подевался наш dnsmasq?"
fi
if [[ ! -f "$DOMAIN_LIST_FILE" ]]; then
log_error "Файл доменных имен ${YELLOW}$DOMAIN_LIST_FILE${RED} не найден!"
exit 1
fi
total_domains=$(grep -cve '^\s*$' "$DOMAIN_LIST_FILE")
if [[ "$total_domains" -eq 0 ]]; then
log_error "Файл ${YELLOW}$DOMAIN_LIST_FILE${RED} пустой. Нечего резолвить."
exit 0
fi
log_info "Начинаем резолвинг доменов Discord..."
update_progress_bar() {
local percent=$1
local filled_length=$(( (PROGRESS_BAR_LENGTH * percent) / 100 ))
local empty_length=$(( PROGRESS_BAR_LENGTH - filled_length ))
local bar
bar=$(printf "%${filled_length}s" | tr ' ' '#')
bar+=$(printf "%${empty_length}s" | tr ' ' '-')
printf "\r${CYAN}[INFO]${NC} Резолвим... [%s] %d%%${NC}" "$bar" "$percent"
}
resolve_to_ip() {
local domain
domain=$(echo "$1" | tr -d '\r')
local output
output=$(dig +short "$domain" A 2>/dev/null | tr -d '\r')
if [[ -z "$output" ]]; then
echo ""
return 1
fi
local resolved_ips=()
while IFS= read -r line; do
line=$(echo "$line" | tr -d '\r')
if [[ $line =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
resolved_ips+=("$line")
else
if new_ips=$(resolve_to_ip "$line"); then
resolved_ips+=($new_ips)
fi
fi
done <<< "$output"
echo "${resolved_ips[@]}" | tr ' ' '\n' | sort -u
return 0
}
mapfile -t domain_array < <(tr -d '\r' < "$DOMAIN_LIST_FILE")
count=0
failed_domains=()
for domain in "${domain_array[@]}"; do
domain=$(echo "$domain" | tr -d '\r' | xargs)
[[ -z "$domain" ]] && continue
if ip_list=$(resolve_to_ip "$domain"); then
if [[ -n "$ip_list" ]]; then
while IFS= read -r ip_entry; do
ip_entry=$(echo "$ip_entry" | tr -d '\r' | xargs)
[[ -n "$ip_entry" ]] && echo "$ip_entry" >> "$IP_LIST_FILE"
done <<< "$ip_list"
ip=$(echo "$ip_list" | head -n1)
else
ip=""
failed_domains+=("$domain")
fi
else
ip=""
failed_domains+=("$domain")
fi
json_entry=$(jq -c -n --arg hostname "$domain" --arg ip "$ip" \
'{hostname: $hostname, ip: $ip}')
if $first_entry; then
first_entry=false
else
echo "," >> "$JSON_OUTPUT_FILE"
fi
echo " $json_entry" >> "$JSON_OUTPUT_FILE"
count=$((count + 1))
percent=$(( (count * 100) / total_domains ))
update_progress_bar "$percent"
done
echo
line_skip
log_success "Резолвинг завершён"
sort -u "$IP_LIST_FILE" -o "$IP_LIST_FILE"
echo "]" >> "$JSON_OUTPUT_FILE"
log_success "Результаты сохранены в файлы:"
echo -e " - $IP_LIST_FILE"
echo -e " - $JSON_OUTPUT_FILE"
line_skip
if [[ ${#failed_domains[@]} -gt 0 ]]; then
log_error "Не удалось зарезолвить следующие домены:"
for d in "${failed_domains[@]}"; do
echo -e " - ${RED}$d${NC}"
done
else
log_success "Все домены успешно зарезолвлены."
fi