AI 代码,DNS入口迁移HTTP服务检查

AI 测试代码,用于检查新旧入口数据是否一致

#!/bin/bash

# 域名列表文件
domain_file="domain-test-list.txt"

# 旧的DNS解析IP
old_ip="10.1.1.1"

# 新的DNS解析IP
new_ip="10.1.1.2"

# 颜色定义
BLUE='\033[0;34m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # 无颜色

# User-Agent 定义
user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36"
# Cookie 定义
cookie="test-cookie=123456"

# 检查域名文件是否存在
if [ ! -f "$domain_file" ]; then
    echo "Domain file not found!"
    exit 1
fi

# 逐行读取域名文件并检查每个域名
while IFS= read -r domain; do
    echo "Checking domain: $domain"

    # 尝试使用 HTTPS 请求
    old_content=$(curl --silent --user-agent "$user_agent" --cookie "$cookie" --resolve "$domain:443:$old_ip" "https://$domain")
    new_content=$(curl --silent --user-agent "$user_agent" --cookie "$cookie" --resolve "$domain:443:$new_ip" "https://$domain")

    # 检查 HTTPS 是否支持
    if [[ -z "$old_content" || -z "$new_content" ]]; then
        echo -e "${YELLOW}WARNING: $domain does not support HTTPS. Trying HTTP...${NC}"

        # 尝试使用 HTTP 请求
        old_content=$(curl --silent --user-agent "$user_agent" --cookie "$cookie" --resolve "$domain:80:$old_ip" "http://$domain")
        new_content=$(curl --silent --user-agent "$user_agent" --cookie "$cookie" --resolve "$domain:80:$new_ip" "http://$domain")

        # 检查 HTTP 是否支持
        if [[ -z "$old_content" || -z "$new_content" ]]; then
            echo -e "${YELLOW}WARNING: $domain does not support HTTP either.${NC}"
            continue
        fi
    fi

    # 检查返回内容是否为空
    if [ -z "$old_content" ] && [ -z "$new_content" ]; then
        echo -e "${RED}FAIL: $domain content from both $old_ip and $new_ip is empty.${NC}"
    elif [ -z "$old_content" ]; then
        echo -e "${RED}FAIL: $domain content from $old_ip is empty.${NC}"
    elif [ -z "$new_content" ]; then
        echo -e "${RED}FAIL: $domain content from $new_ip is empty.${NC}"
    else
        # 对比两个响应数据
        if [ "$old_content" == "$new_content" ]; then
            echo -e "${BLUE}PASS: $domain content matches.${NC}"
        else
            echo -e "${RED}FAIL: $domain content does not match.${NC}"

            # 创建临时文件并写入内容
            timestamp=$(date +"%Y%m%d%H%M%S")
            old_file="/tmp/${domain//./_}_old_${timestamp}.txt"
            new_file="/tmp/${domain//./_}_new_${timestamp}.txt"

            echo "$old_content" > "$old_file"
            echo "$new_content" > "$new_file"

            echo -e "${RED}FAIL: See differences in files: ${old_file}, ${new_file}${NC}"
        fi
    fi
done < "$domain_file"

新建文本 domain-test-list.txt 输入域名列表

bash domain-test.sh

正常返回:

Checking domain: test1.example.com
PASS: test1.example.com content matches.

当前还没有任何评论

写下你最简单的想法