-
Notifications
You must be signed in to change notification settings - Fork 1
/
mainnet_test.sh
executable file
·65 lines (54 loc) · 1.69 KB
/
mainnet_test.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
#!/bin/bash
# File containing the list of hosts with ports to check
input_file="mainnet.txt"
# Timeout duration
timeout=5
# Function to check each host and port
check_host() {
local host_with_port=$1
local host="${host_with_port%@*}"
local address_port="${host_with_port#*@}"
local address="${address_port%:*}"
local port="${address_port#*:}"
echo "Checking $address:$port..."
# Check with Netcat
echo -n " - nc: "
if nc -zv -w $timeout "$address" "$port" &>/dev/null; then
echo "✅ Port $port is open on $address"
else
echo "❌ Port $port is closed on $address or connection timed out"
fi
# Check with curl (only for HTTP/HTTPS ports)
if [[ "$port" == "80" || "$port" == "443" ]]; then
echo -n " - curl: "
if curl -m $timeout -Is "http://$address:$port" &>/dev/null; then
echo "✅ HTTP(S) service is available on $address:$port"
else
echo "❌ HTTP(S) service is unavailable on $address:$port"
fi
fi
# Check with Ping
echo -n " - ping: "
if ping -c 1 -W $timeout "$address" &>/dev/null; then
echo "✅ $address is reachable"
else
echo "❌ $address is unreachable"
fi
# Check DNS resolution with dig
echo -n " - dig: "
if dig +time=$timeout +short "$address" &>/dev/null; then
echo "✅ $address resolves successfully"
else
echo "❌ DNS resolution failed for $address"
fi
echo
}
# Check if the input file exists
if [[ ! -f "$input_file" ]]; then
echo "File $input_file not found!"
exit 1
fi
# Loop through each line in the input file
while IFS= read -r host; do
check_host "$host"
done <"$input_file"