1 changed files with 31 additions and 0 deletions
@ -0,0 +1,31 @@ |
|||
#!/usr/bin/env bash |
|||
|
|||
check_ip() { |
|||
local ip=$1 |
|||
local port=$2 |
|||
local attempts=$3 |
|||
local delay=$4 |
|||
|
|||
local result="" |
|||
local succeeded=0 |
|||
local half_attempts=$((attempts/2)) |
|||
|
|||
for ((i=1; i<=attempts; i++)); do |
|||
result=$(nc -vz -w1 "$ip" "$port" 2>&1) |
|||
if echo "$result" | grep -q "succeeded"; then |
|||
succeeded=$((succeeded+1)) |
|||
fi |
|||
sleep "$delay" |
|||
done |
|||
|
|||
if [ "$succeeded" -gt "$half_attempts" ]; then |
|||
echo "Online" |
|||
else |
|||
echo "Offline" |
|||
fi |
|||
} |
|||
|
|||
while IFS=',' read -r lat lon company city ip status version; do |
|||
new_status=$(check_ip "$ip" 18030 5 2) |
|||
echo "$lat,$lon,$company,$city,$ip,$new_status,$version" |
|||
done < nodes.dat |
Loading…
Reference in new issue