#!/bin/bash

ADDR="要監測的DDNS"
TMPSTR=$(ping -c 1 ${ADDR} | sed '1{s/[^(]*(//;s/).*//;q}')
port=要監測的端口
check_ip=$(nmap $TMPSTR -p $port | grep open | wc -l)

echo "Ping result for ${ADDR}: ${TMPSTR}"

echo "Final IP Address: ${TMPSTR}"  # 移到这里

if [ $check_ip -eq 0 ]; then
  echo "Port ${port} is closed. Initiating update..."
  curl "後台面板更換IP的API"
  systemctl restart nscd
  echo "Update completed."  
fi
