· 7 years ago · Apr 02, 2018, 01:38 AM
1#!/bin/sh
2#==================================================
3# OS Required: Linux with curl
4# Description: CloudXNS DDNS on bash
5# Author: Kuretru
6# Version: 1.1.160913
7# Github: https://github.com/kuretru/CloudXNS-DDNS/
8#==================================================
9
10#API Key
11api_key=""
12
13#Secret Key
14secret_key=""
15
16#Domain name
17#e.g. domain="www.cloudxns.net."
18domain="dongtai1.gubo.org"
19
20#WAN Network Interface Card
21#e.g. interface="" -> If it's empty, CloudXNS will automatic get your public IP
22#or interface="ppp0" -> on tomato
23#or interface="pppoe-wan1" -> on OpenWRT
24interface=""
25
26value=$(curl -s ifconfig.co)
27
28url="https://www.cloudxns.net/api2/ddns"
29time=$(date -R)
30data="{\"domain\":\"${domain}\",\"ip\":\"${value}\",\"line_id\":\"1\"}"
31mac_raw="$api_key$url$data$time$secret_key"
32mac=$(echo -n $mac_raw | md5sum | awk '{print $1}')
33header1="API-KEY:"$api_key
34header2="API-REQUEST-DATE:"$time
35header3="API-HMAC:"$mac
36header4="API-FORMAT:json"
37
38result=$(curl -k -X POST -H $header1 -H "$header2" -H $header3 -H $header4 -d "$data" $url)
39if [[ $(echo $result | grep "success") != "" ]]; then
40 logger -t NOTICE "CloudXNS DDNS success IP address $value"
41fi