Files
dns-server/test_query_modes.sh

97 lines
2.1 KiB
Bash
Raw 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
# 测试三种查询模式
echo "=== 测试三种查询模式 ==="
# 确保dig命令存在
if ! command -v dig &> /dev/null; then
echo "dig命令不存在使用nslookup替代"
USE_DIG=false
else
USE_DIG=true
fi
echo "1. 测试并行请求模式"
echo "修改配置文件为parallel模式"
sed -i 's/"queryMode": "[^"]*"/"queryMode": "parallel"/' config.json
cat config.json | grep queryMode
echo "重启DNS服务器..."
pkill -f "go run main.go"
sleep 2
go run main.go > server.log 2>&1 &
SERVER_PID=$!
echo "服务器进程ID: $SERVER_PID"
sleep 5
if [ -f server.log ]; then
tail -5 server.log
fi
echo "测试DNS查询..."
if $USE_DIG; then
dig @localhost example.com +short
else
nslookup example.com localhost | grep -A 2 "Name:"
fi
echo "2. 测试负载均衡模式"
echo "修改配置文件为loadbalance模式"
sed -i 's/"queryMode": "[^"]*"/"queryMode": "loadbalance"/' config.json
cat config.json | grep queryMode
echo "重启DNS服务器..."
pkill -f "go run main.go"
sleep 2
go run main.go > server.log 2>&1 &
SERVER_PID=$!
echo "服务器进程ID: $SERVER_PID"
sleep 5
if [ -f server.log ]; then
tail -5 server.log
fi
echo "测试DNS查询..."
if $USE_DIG; then
dig @localhost example.com +short
else
nslookup example.com localhost | grep -A 2 "Name:"
fi
echo "3. 测试最快的IP地址模式"
echo "修改配置文件为fastest-ip模式"
sed -i 's/"queryMode": "[^"]*"/"queryMode": "fastest-ip"/' config.json
cat config.json | grep queryMode
echo "重启DNS服务器..."
pkill -f "go run main.go"
sleep 2
go run main.go > server.log 2>&1 &
SERVER_PID=$!
echo "服务器进程ID: $SERVER_PID"
sleep 5
if [ -f server.log ]; then
tail -5 server.log
fi
echo "测试DNS查询..."
if $USE_DIG; then
dig @localhost example.com +short
else
nslookup example.com localhost | grep -A 2 "Name:"
fi
echo "=== 测试完成 ==="
echo "停止DNS服务器..."
pkill -f "go run main.go"
# 删除日志文件
rm -f server.log
echo "恢复默认配置..."
sed -i 's/"queryMode": "[^"]*"/"queryMode": "parallel"/' config.json
cat config.json | grep queryMode