CF-DDNS
This commit is contained in:
parent
08145915e5
commit
3f54d18773
4
cf-ddns/README.md
Normal file
4
cf-ddns/README.md
Normal file
@ -0,0 +1,4 @@
|
||||
# Cloudflare DDNS
|
||||
|
||||
## Requirements
|
||||
`bash curl jq screen`
|
44
cf-ddns/cfddns.sh
Normal file
44
cf-ddns/cfddns.sh
Normal file
@ -0,0 +1,44 @@
|
||||
#!/bin/bash
|
||||
|
||||
#Import Credentials
|
||||
source .env 2> /dev/null
|
||||
|
||||
fetchzoneid(){
|
||||
FETCHZONEID=$(curl -s $CF_API_URL/zones?name=$CF_ROOT_ZONE \
|
||||
-H Content-Type:application/json \
|
||||
-H X-Auth-Key:$CF_API_KEY \
|
||||
-H X-Auth-Email:$CF_EMAIL)
|
||||
CF_ZONE_ID=$(echo $FETCHZONEID | jq -r '.result | .[] | .id')
|
||||
}
|
||||
|
||||
fetchdnsid(){
|
||||
FETCHDNSID=$(curl -s $CF_API_URL/zones/$CF_ZONE_ID/dns_records?name=$CF_DOMAIN \
|
||||
-H Content-Type:application/json \
|
||||
-H X-Auth-Key:$CF_API_KEY \
|
||||
-H X-Auth-Email:$CF_EMAIL)
|
||||
CF_DNS_ID=$(echo $FETCHDNSID | jq -r '.result | .[] | .id')
|
||||
}
|
||||
|
||||
getip(){
|
||||
MY_IP=$(curl -s $WHATISMYIP)
|
||||
}
|
||||
getdatetime(){
|
||||
TIME=$(date)
|
||||
}
|
||||
updateip(){
|
||||
curl -s -X PUT $CF_API_URL/zones/$CF_ZONE_ID/dns_records/$CF_DNS_ID \
|
||||
-H Content-Type:application/json \
|
||||
-H X-Auth-Key:$CF_API_KEY \
|
||||
-H X-Auth-Email:$CF_EMAIL \
|
||||
--data '{"type":"A","name":"'${CF_DOMAIN}'","content":"'${MY_IP}'","ttl":120,"proxied":false}' > /dev/null
|
||||
}
|
||||
|
||||
fetchzoneid
|
||||
fetchdnsid
|
||||
while true; do
|
||||
getip
|
||||
updateip
|
||||
getdatetime
|
||||
(echo $MY_IP - $TIME) | tee -a ip.log
|
||||
sleep $DELAY
|
||||
done
|
8
cf-ddns/env.sample
Normal file
8
cf-ddns/env.sample
Normal file
@ -0,0 +1,8 @@
|
||||
CF_ROOT_ZONE='' # Root domain
|
||||
CF_EMAIL='' #Cloudflare Login email
|
||||
CF_API_KEY='' #Cloudflare API Key, get it here https://dash.cloudflare.com/profile/api-tokens
|
||||
CF_DOMAIN='' # Domain to change IP address of
|
||||
DELAY='600' #Defines how often to check and update IP address
|
||||
|
||||
WHATISMYIP='https://whatismyip.shihaam.me' #Any website that returns vistor IP address
|
||||
CF_API_URL='https://api.cloudflare.com/client/v4' #prolly dont need to change this
|
4
cf-ddns/run-cdddns.sh
Normal file
4
cf-ddns/run-cdddns.sh
Normal file
@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1
|
||||
screen -S ddns -p 0 -X quit
|
||||
screen -S "ddns" -U -m -d bash update-home-ip-cf.sh
|
Loading…
x
Reference in New Issue
Block a user