原文:http://www.dwhd.org/20150519_160959.html

    在CC15上安装成功

    1更换openwrt的源加速地址

    1
    sed -i 's/downloads.openwrt.org/openwrt.legion.pt/' /etc/opkg .conf

    2安装bash shell

    1
    opkg update && opkg install bash

    3将root用户的shell换成bash

    1
    sed -ri 's|^(root:.*:)/bin/.*|\1/bin/bash|' /etc/passwd

    4下载DDNS脚本

    1
    wget http: //www .dwhd.org /script/dnspodDDNS .sh -O /etc/dnspodddns .sh && chmod +x /etc/dnspodddns .sh

    5执行下面的命令 修改几个必要的参数

    1
    2
    vi /etc/dnspodddns .sh
    [ -z "$(grep 'dnspodddns.sh' /var/spool/cron/crontabs/root )" ] && echo "*/1 * * * * /etc/dnspodddns.sh &>/dev/null" >> /var/spool/cron/crontabs/root

    6然后退出ssh 重新登录或者重启下路由

    1
    reboot

     

     

    下面是脚本源码

    01
    02
    03
    04
    05
    06
    07
    08
    09
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    #!/bin/bash
    #########################################################################
    # File Name: dnspodDDNS.sh
    # Author: LookBack
    # Email: 393411264@qq.com
    # Created Time: 2015年03月28日 星期六 23时19分00秒
    #########################################################################
    #
    #        利用DNSPOD官方提供的API,自动更新域名解析记录,
    #        在Netgear 4300 openwrt和CentOS 6系统上测试完美执行,
    #        在其他硬件的openwrt上应该也是可以执行的,
    #        非openwrt系统的不保证脚本的兼容性。
    #        如有任何BUG 请联系我 393411264@qq.com
    #
    #########################################################################
     
    #=======================下方是需要修改的参数信息=============================================
    #DNSPOD 帐号
    DNSPODID= "393411264@qq.com"
    #DNSPOD 密码
    DNSPODPW= "www.05hd.com"
    #DNSPOD 主域名
    DNSPODPD= "05h.com"
    #DNSPOD 二级域名,可以是多个,如下设置DNSPODSDNM[0-n]。有几个就写几个,把多余的删除
    DNSPODSDNM[0]= "openwrt141"
    DNSPODSDNM[1]= "openwrt"
    DNSPODSDNM[2]= "netgear111"
    #=========================下方内容如果不懂请勿修改============================================
    CURL=$( which curl)
    GetID() {
             $CURL -X POST https: //dnsapi .cn /Domain .List -ks -d "login_email=$1&login_password=$2&format=json" | \
    awk -F ',' '{for(i=1;i<=NF;i++) if($i~/"id":[0-9]+/ || $i~/"name":".*"/) {print $i}}' | \
    awk '{if (NR%2==0){print $0} else {printf"%s ",$0}}' | sed 's/"domains":\[//' | \
    awk -F ':| |"' '{print $9,$4}' > /tmp/dnspodDomain
             while read line; do
                     if [ "$(awk '{print$1}' <<< $line)A" = "${DNSPODPD}A" ]; then
                             DNSPODPDID=$( awk '{print$2}' <<< $line)
                             break
                     fi
             done < /tmp/dnspodDomain
     
             $CURL -X POST https: //dnsapi .cn /Record .List -ks -d "login_email=$1&login_password=$2&format=json&domain_id=$DNSPODPDID" | \
    sed 's/.*},"records":\[//' | awk -F ',' '{for(i=1;i<=NF;i++) if($i~/"id":"[0-9]+"/ || $i~/"name":".*"/) {print $i}}' | \
    awk '{if (NR%2==0){print $0} else {printf"%s ",$0}}' | awk -F '"' '{print $8,$4}' > /tmp/dnspodRecord
             while read line; do
                     for i in ` seq 1 ${ #DNSPODSDNM[@]}`; do
                             i=$[$i-1]
                             [ "$(awk '{print$1}' <<< $line)A" = "${DNSPODSDNM[$i]}A" ] && DNSPODSDID[$i]=$( awk '{print$2}' <<< $line) && break
                     done
             done < /tmp/dnspodRecord
    }
     
    StartRun() {
             WanIP=$($CURL -s ip.cn | grep -Eo '([0-9]{1,3}[\.]){3}[0-9]{1,3}' )
             DNSPODIP=$($CURL -X POST https: //dnsapi .cn /Record .Info -ks -d \
    "login_email=$1&login_password=$2&format=json&domain_id=$3&record_id=${DNSPODSDID[0]}" | \
    grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}' )
    #awk -F':|,|"' '{for(i=1;i<=NF;i++)if($i~/^([0-9]{1,3}\.){3}[0-9]{1,3}$/){print$i;break}}')
             [ -z $WanIP ] && exit 1
             [ -z $DNSPODIP ] && exit 1
             :> /tmp/dnspodDomain && :> /tmp/dnspodRecord
    }
     
    UploadIP() {
             [ "${3}A" != "${4}A" ]
             if [ "A$?" = "A0" ]; then
                     for i in ` seq 1 ${ #DNSPODSDNM[@]}`; do
                             i=$[$i-1]
                             $CURL -X POST https: //dnsapi .cn /Record .Modify -ks -d \
    "login_email=$1&login_password=$2& format =json&domain_id=$5\
    &record_id= ${DNSPODSDID[$i]}&sub_domain=${DNSPODSDNM[$i]}&value=$3\
    &record_type=A&record_line=默认" &> /dev/null
                             echo "$(date " +%F %H:%M:%S ") Domain ${DNSPODSDNM[$i]}.$DNSPODPD A Record Update To $3" >> /var/log/dnspod .log
                     done
             fi
    }
     
    RUN() {
             GetID $1 $2
             StartRun $1 $2 $DNSPODPDID
             UploadIP $1 $2 ${WanIP} ${DNSPODIP} $DNSPODPDID ${DNSPODSDID[*]}
    }
     
    RUN $DNSPODID $DNSPODPW $DNSPODPDID