公司设备设置了映射,但是公网ip老是变化,于是利用serverchan写了一个bash脚本。
脚本名称 pushIptowechat.sh
#!/bin/bash
ip=$(curl ip.sb)
sckey="SCU********************************************************"
pushurl="https://sc.ftqq.com/$sckey.send?desp=DeviceWanIp&text="
curl ${pushurl}${ip}
while :
do
sleep 10
newip=$(curl ip.sb)
if [ "$ip" = "$newip" ] ;then
echo "ip is not changed.currentip is ${ip}"
else
echo "ip has changed,new ip is ${newip}"
ip=${newip}
curl ${pushurl}${ip}
fi
done
sckey
需要自己登陆微信去获取 Server Chan官网
由于程序是一个死循环之类的,所以只需要开机启动即可。使用crontab -e
来添加开机任务
/bin/bash /home/root/pushIptowechat.sh >/dev/null 2>&1 &