Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
dnsname=192.168.1.100:5380
username=admin
password=Uenpay2023
tokenname=`curl -s "http://$dnsname/api/user/createToken?user=$username&pass=$password&tokenName==zhengyu"|jq .token|sed 's#"##g'`
domainlist=(
  uenpay.com
  weifumao.com
  5ubp.com
  zhuduan.vip
  merrymate.cn
)

for domains in ${domainlist[@]}
do
  status=`curl -s "http://$dnsname/api/zones/options/get?token=${tokenname}&zone=$domains&includeAvailableTsigKeyNames=true"|jq .status|sed 's#"##g'`
  if [ $status = "ok" ];then
    echo "$domains 已存在已存在,请登陆控制台确认"
  else
    curl "http://$dnsname/api/zones/create?token=${tokenname}&zone=$domains&type=Primary"
    #创建Conditional Forwarder Zone(只能用于单点dns服务)
    #curl "http://$dnsname/api/zones/create?token=${tokenname}&zone=$domains&type=Forwarder&forwarder=223.5.5.5"
  fi
  ##添加A记录
    cat ${domains}-*.txt|awk '$2 == "A" { print }'|while read line;
    do
      domain=`echo $line|awk '{print $1}'`
      ip=`echo $line|awk '{print $3}'`
      curl -s "http://$dnsname/api/zones/records/add?token=$tokenname&domain=$domain.$domains&zone=$domains&type=A&ttl=600&overwrite=true&ipAddress=$ip"
    done
    ##添加CNAME记录
    cat ${domains}-*.txt|awk '$2 == "CNAME" { print }'|while read line;
    do
      domain=`echo $line|awk '{print $1}'`
      cname=`echo $line|awk '{print $3}'`
      curl -s "http://$dnsname/api/zones/records/add?token=$tokenname&domain=$domain.$domains&zone=$domains&type=CNAME&ttl=600&overwrite=true&cname=$cname"
    done
  fi
done


通过接口获取当前所有域名对象

Code Block
dnsname=192.168.1.100:5380
username=admin
password=Uenpay2023
tokenname=`curl -s "http://$dnsname/api/user/createToken?user=$username&pass=$password&tokenName==zhengyu"|jq .token|sed 's#"##g'`
curl -s "http://$dnsname/api/zones/list?token=${tokenname}&"|jq .response.zones|jq  -r '.[]'|jq .name|grep -Ev "arpa|localhost"|sed 's#"##g'