-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhostname_examiner.sh
109 lines (101 loc) · 4.79 KB
/
hostname_examiner.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
#!/bin/bash
echo -e "This script aims to examine the reliability of dynamic DNS of our partners. The main goal: to prove that the previous parner's IP is still reachable, even though it's not completely there when we search using the \"dig\" command."
mkdir -p results
mkdir -p ip_target
IFS=" " read -r -a ips_store <<< ""
endpoint="api-mt.thunes.com api.bni-ecollection.com api.bni.co.id dev.bni-ecollection.com apidev.bni.co.id api.danamon.co.id aping-ideal.dbs.com aping.dbs.id"
IFS=" " read -r -a endpoint <<< "$endpoint"
endpointlength=${#endpoint[@]}
for ((counter = 0; counter < endpointlength; counter++))
do
# Log rotate for each endpoint
logname="result.log"
if [ -f "results/$logname" ]; then
namerotator=$(ls results/ | grep -Po "${logname}[\.0-9]*" | tail -n 1 | awk "{sub(/${logname}[\.]*/,\"\")}1")
namerotator=$((namerotator+1))
logname="$logname.$namerotator"
echo $logname
else
logname="result.log"
fi
# Reset
IFS=" " read -r -a ips_store <<< ""
echo -e "HOSTNAME: ${endpoint[$counter]}"
echo -e "HOSTNAME: ${endpoint[$counter]}" >> results/$logname
loopcounter=0
timeoutcounter=0
counter2xx=0
counter3xx=0
counter4xx=0
counter5xx=0
while [ $loopcounter -lt 200 ]
do
# Filter and map hostname's ips
mapfile -t value_store < <(dig +short "${endpoint[$counter]}" | grep -oE '\b((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|$)){4}\b')
value_store_length=${#value_store[@]}
if [[ "$value_store_length" == 1 ]]; then
lists=""
if [[ ! " ${ips_store[*]} " =~ " ${value_store[0]} " ]]; then
ips_store+=("${value_store[0]}")
length=${#ips_store[@]}
for ((l = 0; l < length; l++))
do
lists+="${ips_store[$l]}\n"
done
if [[ "$loopcounter" != 0 ]]; then
echo -e "FOUND NEW IP ${value_store[0]}\nIP LISTS:\n$lists"
echo -e "FOUND NEW IP ${value_store[0]}\nIP LISTS:\n$lists" >> results/$logname
fi
fi
# Sequence/single curl
for ((i = 0; i < ${#ips_store[@]}; i++))
do
ip="${ips_store[$i]}"
status_code=$(curl -sI https://$ip --insecure -m 2 | grep -Po "[0-9]{2,3}+" | head -n 1)
if [ -n "$status_code" ]; then
echo "[$(date)] ${ips_store[$i]} $status_code"
echo "[$(date)] ${ips_store[$i]} $status_code" >> results/$logname
if [[ "$status_code" =~ [5][0][0-9] ]]; then
counter5xx=$((counter5xx+1))
elif [[ "$status_code" =~ [4][0][0-9] ]]; then
counter4xx=$((counter4xx+1))
elif [[ "$status_code" =~ [3][0][0-9] ]]; then
counter3xx=$((counter3xx+1))
elif [[ "$status_code" =~ [2][0][0-9] ]]; then
counter2xx=$((counter2xx+1))
fi
else
echo "[$(date)] ${ips_store[$i]} timeout"
echo "[$(date)] ${ips_store[$i]} timeout" >> results/$logname
timeoutcounter=$((timeoutcounter+1))
fi
done
else
for ((ipcounter = 0; ipcounter < value_store_length; ipcounter++))
do
lists=""
if [[ ! " ${ips_store[*]} " =~ " ${value_store[$ipcounter]} " ]]; then
length=${#ips_store[@]}
# Store value
ips_store+=("${value_store[$ipcounter]}")
lists+="${ips_store[$l]}\n"
if [[ "$loopcounter" != 0 ]]; then
echo -e "FOUND NEW IP ${value_store[$ipcounter]}\nIP LISTS:\n$lists"
echo -e "FOUND NEW IP ${value_store[$ipcounter]}\nIP LISTS:\n$lists" >> results/$logname
fi
fi
done
# Parallel curl
xargs -P 1 -n 1 -I@ bash -c "curl -sI https://@ --insecure -m 2 | grep -Po \"[0-9]{2,3}+\" | head -n 1 && echo \"[$(date)] @ \" >> results/$logname" < ip_target/ip_target_"${endpoint[$counter]}".txt >> results/$logname
fi
# Save target ip to the file
printf "%s\n" "${ips_store[@]}" > ip_target/ip_target_"${endpoint[$counter]}".txt
((loopcounter=loopcounter+1))
if [[ "$timeoutcounter" -gt 10 || "$counter5xx" -gt 10 ]]; then
break;
fi
sleep 0.5
done
echo -e "Timeout: $timeoutcounter\n2XX: $counter2xx\n3XX: $counter3xx\n4XX: $counter4xx\n5XX: $counter5xx"
echo -e "Timeout: $timeoutcounter\n2XX: $counter2xx\n3XX: $counter3xx\n4XX: $counter4xx\n5XX: $counter5xx" >> results/$logname
done