1 2 3 4 5 6 7 8 9 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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
dnspod_ddnsipv6_id="123456" dnspod_ddnsipv6_token="**1234abc**" dnspod_ddnsipv6_ttl="600" dnspod_ddnsipv6_domain='test.com' dnspod_ddnsipv6_subdomain='file' local_net="eth0"
if [ "$dnspod_ddnsipv6_record" = "@" ] then dnspod_ddnsipv6_name=$dnspod_ddnsipv6_domain else dnspod_ddnsipv6_name=$dnspod_ddnsipv6_subdomain.$dnspod_ddnsipv6_domain fi
die () { echo "Error: unable to find [public IPv6 address], please use the 'ip addr' command or query the network panel of the system to check the network card, and fill in the name of the network card with the IPv6 address in the 'local_net' position in the command file." >&2 echo "IP地址提取错误: 在指定的网络适配器上[$local_net]找不到<公网IPv6地址>(不是fe80开头),请使用'ip addr'命令或在系统的网络面板查询有公网IP的网络适配器,然后在脚本的[local_net]中用填写网络适配器的名称。" >&2 exit }
ipv6_list=`ip addr show $local_net | grep "inet6.*global" | awk '{print $2}' | awk -F"/" '{print $1}'` || die
for ipv6 in ${ipv6_list[@]} do if [[ "$ipv6" =~ ^fe80.* ]] then continue else echo select IP: $ipv6 >&1 break fi done
if [ "$ipv6" == "" ] || [[ "$ipv6" =~ ^fe80.* ]] then die fi
dns_server_info=`nslookup -query=AAAA $dnspod_ddnsipv6_name 2>&1`
dns_server_ipv6=`echo "$dns_server_info" | grep 'address ' | awk '{print $NF}'` if [ "$dns_server_ipv6" = "" ] then dns_server_ipv6=`echo "$dns_server_info" | grep 'Address: ' | awk '{print $NF}'` fi if [ "$?" -eq "0" ] then echo "DNS server IP: $dns_server_ipv6" >&1
if [ "$ipv6" = "$dns_server_ipv6" ] then echo "The address is the same as the DNS server." >&1 fi unset dnspod_ddnsipv6_record_id else dnspod_ddnsipv6_record_id="1" fi
send_request() { local type="$1" local data="login_token=$dnspod_ddnsipv6_id,$dnspod_ddnsipv6_token&domain=$dnspod_ddnsipv6_domain&sub_domain=$dnspod_ddnsipv6_subdomain$2" return_info=`curl -X POST "https://dnsapi.cn/$type" -d "$data" 2> /dev/null` }
query_recordid() { send_request "Record.List" "" }
update_record() { send_request "Record.Modify" "&record_type=AAAA&record_line=默认&ttl=$dnspod_ddnsipv6_ttl&value=$ipv6&record_id=$dnspod_ddnsipv6_record_id" }
add_record() { send_request "Record.Create" "&record_type=AAAA&record_line=默认&ttl=$dnspod_ddnsipv6_ttl&value=$ipv6" }
if [ "$dnspod_ddnsipv6_record_id" = "" ] then echo "seem exists, try update." >&1 query_recordid code=`echo $return_info | awk -F \"code\":\" '{print $2}' | awk -F \",\"message\" '{print $1}'` echo "return code $code" >&1 if [ "$code" = "1" ] then dnspod_ddnsipv6_record_id=`echo $return_info | awk -F \"records\":.{\"id\":\" '{print $2}' | awk -F \",\"ttl\" '{print $1}'` update_record echo "update sucessful" >&1 else echo "error code return, domain not exists, try add." >&1 add_record echo "add sucessful." >&1 fi else echo "domain not exists, try add." add_record echo "add sucessful" >&1 fi
|