-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathip.sh
More file actions
26 lines (24 loc) · 868 Bytes
/
ip.sh
File metadata and controls
26 lines (24 loc) · 868 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/bash
dirfile='/volume1/docker/nark/ip_change'
new_ip=`curl ip.3322.net` #获取新公网ip
log="/volume1/docker/nark/tool.log"
datetime=`date '+%Y-%m-%d %H:%M:%S'`
#判断文件是否存在
if [ ! -f "$dirfile" ]; then
touch "$file"
echo "1.1.1.1" > $dirfile
fi
#判断new_ip是否获取
if [ ! -n "$new_ip" ]; then
echo "$datetime 公网IP获取失败,检查'curl ip.3322.net' " >> $log
exit 1
fi
old_ip=`cat $dirfile` #查看旧ip
if [ "$new_ip" = "$old_ip" ]; then
echo "$datetime IP正常 - true " >> $log
else
echo $new_ip > $dirfile
echo "IP已经发生变化, 新IP: $new_ip 旧IP: $old_ip " | docker restart nark
echo "$datetime IP已经发生变化 - error 新IP :$new_ip IP: $old_ip " >> $log
fi
curl "http://43.1XX.XX.XX:20086/push?token=dahuilang&message=IP变动检测,新IP:$new_ip,旧IP:$old_ip"