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
| package main
import ( "flag" "fmt" "strconv"
"github.com/aliyun/alibaba-cloud-sdk-go/sdk" "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials" "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" alidns "github.com/aliyun/alibaba-cloud-sdk-go/services/alidns"
"encoding/csv" "os" )
func main() { domain := flag.String("domain", "", "domain") flag.Parse()
var ak string = "" var sk string = ""
config := sdk.NewConfig()
credential := credentials.NewAccessKeyCredential(ak, sk) client, err := alidns.NewClientWithOptions("cn-hangzhou", config, credential) if err != nil { panic(err) }
request := alidns.CreateDescribeDomainRecordsRequest()
request.Scheme = "https"
request.DomainName = *domain request.PageNumber = requests.NewInteger(1) request.PageSize = requests.NewInteger(500)
response, err := client.DescribeDomainRecords(request) if err != nil { fmt.Print(err.Error()) }
file, err := os.OpenFile(*domain+".csv", os.O_CREATE|os.O_RDWR, 0644) if err != nil { fmt.Println("open file is failed, err: ", err) } defer file.Close() file.WriteString("\xEF\xBB\xBF") w := csv.NewWriter(file) w.Write([]string{"index", "name", "value", "status", "type"})
for index, value := range response.DomainRecords.Record { index := strconv.Itoa(index) w.Write([]string{index, value.RR, value.Value, value.Status, value.Type})
}
if response.TotalCount > 500 { request.PageNumber = requests.NewInteger(2) response_new, err := client.DescribeDomainRecords(request) if err != nil { fmt.Print(err.Error()) }
for index, value := range response_new.DomainRecords.Record { index := strconv.Itoa(index) w.Write([]string{index, value.RR, value.Value, value.Status, value.Type})
}
} w.Flush() }
|