update_cdmon.sh
· 691 B · Bash
Raw
#!/bin/bash
APIKEY=""
DOMAIN=""
IP_FILE="ip.txt"
# Get current public IP
NEW_IP=$(curl -s https://api.ipify.org)
if [ -f $IP_FILE ]; then
OLD_IP=$(cat $IP_FILE)
if [ $NEW_IP == $OLD_IP ]; then
echo "IP has not changed."
exit 0
fi
fi
curl --include \
--request POST \
--header "Content-Type: application/json" \
--header "Accept: application/json" \
--header "apikey: $APIKEY" \
--data-binary "{\"data\": {\"domain\": \"$DOMAIN\", \"current\": {\"host\": \"@\", \"type\": \"A\"}, \"new\": {\"ttl\": 1100, \"destination\": \"$NEW_IP\"}}}" \
https://api-domains.cdmon.services/api-domains/dnsrecords/edit
echo "$NEW_IP" > $IP_FILE
| 1 | #!/bin/bash |
| 2 | |
| 3 | APIKEY="" |
| 4 | DOMAIN="" |
| 5 | |
| 6 | IP_FILE="ip.txt" |
| 7 | |
| 8 | # Get current public IP |
| 9 | NEW_IP=$(curl -s https://api.ipify.org) |
| 10 | |
| 11 | if [ -f $IP_FILE ]; then |
| 12 | OLD_IP=$(cat $IP_FILE) |
| 13 | if [ $NEW_IP == $OLD_IP ]; then |
| 14 | echo "IP has not changed." |
| 15 | exit 0 |
| 16 | fi |
| 17 | fi |
| 18 | |
| 19 | curl --include \ |
| 20 | --request POST \ |
| 21 | --header "Content-Type: application/json" \ |
| 22 | --header "Accept: application/json" \ |
| 23 | --header "apikey: $APIKEY" \ |
| 24 | --data-binary "{\"data\": {\"domain\": \"$DOMAIN\", \"current\": {\"host\": \"@\", \"type\": \"A\"}, \"new\": {\"ttl\": 1100, \"destination\": \"$NEW_IP\"}}}" \ |
| 25 | https://api-domains.cdmon.services/api-domains/dnsrecords/edit |
| 26 | |
| 27 | echo "$NEW_IP" > $IP_FILE |