通过dnspod api实现动态ddns更新ip,shell脚本如下:
#!/bin/sh
token="xxxxxxxxxxxxxxxx"
domain="haiyun.me"
name="test"
if [ "$1" != "${1#*[0-9].[0-9]}" ]; then
curl -s -d "login_token=$token&format=json&domain=$domain" "https://dnsapi.cn/Record.List" -o /tmp/dns.txt
if grep -q '"code":"1"' /tmp/dns.txt; then
if grep -q "\"name\":\"$name\"" /tmp/dns.txt; then
ip=`jsonfilter -i /tmp/dns.txt -e "@.records[@.name='$name'].value"`
echo $ip
ip_state=$?
id=`jsonfilter -i /tmp/dns.txt -e "@.records[@.name='$name'].id"`
id_state=$?
if [ $ip_state -eq 0 ] && [ $id_state -eq 0 ] && [ "$ip" != "$1" ] && [ "$id" != "" ];then
echo "mod ip"
if curl -s -d "login_token=$token&format=json&domain=$domain&record_id=$id&value=$1&record_type=A&record_line_id=0&sub_domain=$name" https://dnsapi.cn/Record.Modify|grep -q '"code":"1"';then
echo "sus"
fi
fi
else
echo "add ip"
if curl -s -d "login_token=$token&format=json&domain=$domain&sub_domain=$name&record_type=A&record_line_id=0&value=$1" https://dnsapi.cn/Record.Create|grep -q '"code":"1"';then
echo "sus"
fi
fi
fi
else
logger -t ddns "invalid IP address $1"
fi
在/lib/netifd/ppp-up文件内调用上面的脚本,当pppoe网络连接成功时会执行此文件,$4变量为pppoe连接的本地IP。
/usr/bin/update-ip.sh $4 > /dev/null 2>&1 &