Home / 开发 / golang 请求api获取whois信息
仅供参考,调用的whois.263.tw
//获取域名whois
func GetDomainInfoHtml(domain string) (string, error) {
req := httplib.Get("https://whois.263.tw/"+domain).SetTimeout(20*time.Second, 20*time.Second).SetProxy(func(*http.Request) (*url.URL, error) { return url.Parse("http://127.0.0.1:10809") })
htmlStr, err := req.String()
return htmlStr, err
}
htmlStr, err := GetDomainInfoHtml(v.Host)
if err != nil {
fmt.Println("请求失败", err.Error())
}
if strings.Contains(htmlStr, "No matching record.") {
fmt.Println("api未支持此域名查询")
}
if strings.Contains(htmlStr, "No match for") {
fmt.Println("可注册")
}
if strings.Contains(htmlStr, "Domain Status") {
doc, err := goquery.NewDocumentFromReader(bytes.NewBufferString(htmlStr))
if err != nil {
fmt.Println("创建goquery失败", err.Error())
} else {
whoisStr := doc.Find("pre").Text()
// fmt.Println(whoisStr)
re1 := regexp.MustCompile(`Registry Expiry Date: (.*)Z`)
expiryDate := strings.ReplaceAll(re1.FindString(whoisStr), "Registry Expiry Date: ", "")
// fmt.Println(expiryDate)
re2 := regexp.MustCompile(`Creation Date: (.*)Z`)
createDate := strings.ReplaceAll(re2.FindString(whoisStr), "Creation Date: ", "")
re3 := regexp.MustCompile(`Registrar URL: (.*)`)
registrarUrl := strings.ReplaceAll(re3.FindString(whoisStr), "Registrar URL: ", "")
registrarUrl = strings.ReplaceAll(registrarUrl, "\n", "")
}
}