#!/bin/bash # 修复版服务器 - 绑定所有接口 SERVER_PORT=25555 LOG_FILE="/tmp/server_fixed.log" echo "启动修复版服务器(绑定所有接口)..." while true; do echo "$(date): 等待客户端连接 0.0.0.0:$SERVER_PORT..." | tee -a "$LOG_FILE" # 使用-l 和 -k 参数,绑定所有接口并保持监听 nc -l -k -p $SERVER_PORT -s 0.0.0.0 -c ' client_ip=$(echo $SSH_CLIENT | awk "{print \$1}") if [[ -z "$client_ip" ]]; then client_ip="unknown" fi read -r data timestamp=$(date "+%Y-%m-%d %H:%M:%S") echo "收到来自 $client_ip 的数据: $data" | tee -a /tmp/server_debug.log if echo "$data" | grep -q "HEARTBEAT|"; then IFS="|" read -r heartbeat serial hostname system <<< "$data" # 记录到临时文件 echo "$serial|$client_ip|$hostname|$system|$timestamp" >> /tmp/clients_debug.txt echo "ACK:OK" echo "✅ 客户端 $serial 连接成功 - $hostname ($client_ip)" | tee -a "$LOG_FILE" else echo "ACK:UNKNOWN_COMMAND" fi ' sleep 1 done