forked from srvrco/getssl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdns_del_dnspod
executable file
·37 lines (27 loc) · 1.39 KB
/
dns_del_dnspod
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
#!/bin/bash
# need to add your email address and key to dnspod below
key=${DNSPOD_API_KEY:-}
fulldomain="$1"
NumParts=$(echo "$fulldomain" | awk -F"." '{print NF}')
if [[ $NumParts -gt 2 ]]; then
domain=$(echo "$fulldomain" | awk -F\. '{print $(NF-1) FS $NF}')
# txtname="_acme-challenge$(echo "$fulldomain" | awk -F\. '{for (i=1; i<NF-1; i++) printf "." $i}')"
else
domain=$fulldomain
# txtname="_acme-challenge"
fi
response=$(curl --silent -X POST "https://dnsapi.cn/Domain.List" \
-H "Accept: application/json" -H "User-Agent: getssl/0.1" -H "application/x-www-form-urlencoded" \
-d "login_token=${key}&format=json" )
domain_id=$(echo "$response" | egrep -o "[^{]*\"name\":\"${domain}\"[^}]*"|grep -oP '\"id\":\K[^,]+')
response=$(curl --silent -X POST "https://dnsapi.cn/Record.List" \
-H "Accept: application/json" -H "User-Agent: getssl/0.1" -H "application/x-www-form-urlencoded" \
-d "login_token=${key}&format=json&domain_id=${domain_id}" )
zone_ids=$(echo "$response" | egrep -o "[^{]*\"type\":\"TXT\"[^}]*" | grep -oP '\"id\":"\K[^"]+')
ids=( $zone_ids )
# loop though all IDs ( if more than one )
for id in "${ids[@]}"; do
response=$(curl --silent -X POST "https://dnsapi.cn/Record.Remove" \
-H "Accept: application/json" -H "User-Agent: getssl/0.1" -H "application/x-www-form-urlencoded" \
-d "login_token=${key}&format=json&domain_id=${domain_id}&record_id=${id}")
done