ipprobe/probe.sh
2024-01-13 16:26:14 +08:00

41 lines
1.3 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
mkdir -p result
mkdir -p use
# 计算文件的行数
total_lines=$(cat result/*.csv | wc -l)
# 遍历result文件夹中的所有csv文件
for file in result/*.csv
do
# 从csv文件中读取每一行并显示进度
cat "$file" | pv -l -s $total_lines | while IFS= read -r line
do
# 将每一行分割成多个字段
IFS=',' read -ra fields <<< "$line"
# 遍历每个字段
for field in "${fields[@]}"
do
# 去除字段两边的空格
field=$(echo $field | xargs)
# 检查字段是否为有效的IPv4地址
if [[ $field =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
# 使用curl命令测试ip地址
status_code=$(curl --resolve cloudflare.com:443:$field --insecure https://cloudflare.com/cdn-cgi/trace -o /dev/null -w '%{http_code}' -s)
# 如果状态码为200将ip地址保存到use.txt文件中
if [ "$status_code" -eq 200 ]
then
echo "IP $field is available"
echo $field >> use/use.txt
else
echo "IP $field is not available"
fi
else
# 如果字段不是有效的IPv4地址跳出循环
break
fi
done
done
done