1. 至Gandi申請APIKEY
  2. 將下述程式碼存成bash script 並設定排程即可
#!/bin/sh
ip=$(/sbin/ifconfig ppp0 | grep 'inet' | cut -d: -f2 | awk '{ print $2}')
APIKEY="你Gandi的API KEY"
DOMAIN="你的domain"
HOST="你要更新的主機名稱,不含domain"
echo "pppoe IP: $ip"
lastip=$(cat /home/pi/lastip)
if [ -z $lastip ]
then
   lastip="0.0.0.0"
fi

if [ "$ip" != "$lastip" ]
then
curl -X PUT -H "Content-Type: application/json"\
     -H "X-Api-Key:$APIKEY"\
     -d '{"rrset_name":"'$HOST'",
        "rrset_type":"A",
	"rrset_ttl":300,
	"rrset_values": ["'$ip'"]}'\
	https://dns.api.gandi.net/api/v5/domains/$DOMAIN/records/$HOST/A
	echo "\n"
    
     echo $ip > /home/pi/lastip	
else
     echo "no change"

fi

By Ray Lee (System Analyst)

iDempeire ERP Contributor, 經濟部中小企業處財務管理顧問 李寶瑞

Leave a Reply

Your email address will not be published. Required fields are marked *