cloudflare.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/bin/bash
  2. red='\e[1;31m'
  3. green='\e[0;32m'
  4. NC='\e[0m'
  5. MYIP=$(wget -qO- icanhazip.com);
  6. echo "Script By geo"
  7. clear
  8. apt install jq curl -y
  9. DOMAIN=aidan.my
  10. sub=$(</dev/urandom tr -dc a-z0-9 | head -c4)
  11. SUB_DOMAIN=${sub}.aidan.my
  12. CF_ID=irwan@aidan.my
  13. CF_KEY=6779dc3c10a378ea902334cc205b5181
  14. set -euo pipefail
  15. IP=$(wget -qO- icanhazip.com);
  16. echo "Updating DNS for ${SUB_DOMAIN}..."
  17. ZONE=$(curl -sLX GET "https://api.cloudflare.com/client/v4/zones?name=${DOMAIN}&status=active" \
  18. -H "X-Auth-Email: ${CF_ID}" \
  19. -H "X-Auth-Key: ${CF_KEY}" \
  20. -H "Content-Type: application/json" | jq -r .result[0].id)
  21. RECORD=$(curl -sLX GET "https://api.cloudflare.com/client/v4/zones/${ZONE}/dns_records?name=${SUB_DOMAIN}" \
  22. -H "X-Auth-Email: ${CF_ID}" \
  23. -H "X-Auth-Key: ${CF_KEY}" \
  24. -H "Content-Type: application/json" | jq -r .result[0].id)
  25. if [[ "${#RECORD}" -le 10 ]]; then
  26. RECORD=$(curl -sLX POST "https://api.cloudflare.com/client/v4/zones/${ZONE}/dns_records" \
  27. -H "X-Auth-Email: ${CF_ID}" \
  28. -H "X-Auth-Key: ${CF_KEY}" \
  29. -H "Content-Type: application/json" \
  30. --data '{"type":"A","name":"'${SUB_DOMAIN}'","content":"'${IP}'","ttl":120,"proxied":false}' | jq -r .result.id)
  31. fi
  32. RESULT=$(curl -sLX PUT "https://api.cloudflare.com/client/v4/zones/${ZONE}/dns_records/${RECORD}" \
  33. -H "X-Auth-Email: ${CF_ID}" \
  34. -H "X-Auth-Key: ${CF_KEY}" \
  35. -H "Content-Type: application/json" \
  36. --data '{"type":"A","name":"'${SUB_DOMAIN}'","content":"'${IP}'","ttl":120,"proxied":false}')
  37. echo "Host : $SUB_DOMAIN"
  38. echo $SUB_DOMAIN > /root/domain
  39. rm -f /root/cf.sh