
- 至Gandi申請APIKEY
- 將下述程式碼存成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
English Version

- Apply for an API KEY from Gandi
- Save the following code as a bash script and set up a scheduled task (cron job)
#!/bin/sh
ip=$(/sbin/ifconfig ppp0 | grep 'inet' | cut -d: -f2 | awk '{ print $2}')
APIKEY="Your Gandi API KEY"
DOMAIN="Your domain"
HOST="The hostname to update, without the 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
日本語版

- GandiでAPIKEYを申請する
- 以下のコードをbashスクリプトとして保存し、スケジュールタスク(cronジョブ)を設定する
#!/bin/sh
ip=$(/sbin/ifconfig ppp0 | grep 'inet' | cut -d: -f2 | awk '{ print $2}')
APIKEY="あなたのGandi API KEY"
DOMAIN="あなたのドメイン"
HOST="更新したいホスト名(ドメインを含まない)"
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