if [ $CURRENT_IP != $LAST_IP ]; then
调用DDNS服务商API更新记录
curl https://your-ddns-provider.com/update?hostname=yourdomain&myip=$CURRENT_IP
echo $CURRENT_IP /tmp/last_ip.txt
fi
3、应用场景
远程访问
家庭网络远程桌面
监控摄像头远程查看
NAS设备外网访问
网络测试
IP变更监控
网络连通性测试
地理位置检测
4、注意事项
频率限制
python
import time
import requests
def ip_monitor(interval=300): 5分钟检查一次
while True:
try:
ip = requests.get('http://icanhazip.com', timeout=10).text.strip()
print(fCurrent IP: {ip})
time.sleep(interval)
except Exception as e:
print(fError: {e})
time.sleep(60) 出错后等待1分钟