130 lines
4.7 KiB
Go
130 lines
4.7 KiB
Go
package whois
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func TestWhoisInfo(t *testing.T) {
|
|
c := NewClient()
|
|
domain := "who.int"
|
|
h, err := c.Whois(domain)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
os.WriteFile("./bin/"+domain+".txt", []byte(h.RawData()), 0644)
|
|
fmt.Println("Domain:", h.Domain())
|
|
fmt.Println("Exists:", h.Exists())
|
|
fmt.Println("RegistrarDate:", h.RegisterDate())
|
|
fmt.Println("ExpireDate:", h.ExpireDate())
|
|
fmt.Println("UpdateDate:", h.UpdateDate())
|
|
fmt.Println("Status:", h.Status())
|
|
fmt.Println("NsServers:", h.NsServers())
|
|
fmt.Println("NsIp:", h.NsIps())
|
|
fmt.Println("Dnssec:", h.Dnssec())
|
|
fmt.Println("WhoisSer:", h.WhoisSer())
|
|
fmt.Println("IanaID:", h.IanaID())
|
|
fmt.Println("======RegisterInfo=======")
|
|
fmt.Println("Name:", h.RegisterInfo().Name)
|
|
fmt.Println("Organization:", h.RegisterInfo().Org)
|
|
fmt.Println("Addr:", h.RegisterInfo().Addr)
|
|
fmt.Println("State:", h.RegisterInfo().State)
|
|
fmt.Println("Country:", h.RegisterInfo().Country)
|
|
fmt.Println("Email:", h.RegisterInfo().Email)
|
|
fmt.Println("Phone:", h.RegisterInfo().Phone)
|
|
fmt.Println("Fax:", h.RegisterInfo().Fax)
|
|
fmt.Println("======AdminInfo=======")
|
|
fmt.Println("Name:", h.AdminInfo().Name)
|
|
fmt.Println("Organization:", h.AdminInfo().Org)
|
|
fmt.Println("Addr:", h.AdminInfo().Addr)
|
|
fmt.Println("State:", h.AdminInfo().State)
|
|
fmt.Println("Country:", h.AdminInfo().Country)
|
|
fmt.Println("Email:", h.AdminInfo().Email)
|
|
fmt.Println("Phone:", h.AdminInfo().Phone)
|
|
fmt.Println("Fax:", h.AdminInfo().Fax)
|
|
fmt.Println("======TechInfo=======")
|
|
fmt.Println("Name:", h.TechInfo().Name)
|
|
fmt.Println("Organization:", h.TechInfo().Org)
|
|
fmt.Println("Addr:", h.TechInfo().Addr)
|
|
fmt.Println("State:", h.TechInfo().State)
|
|
fmt.Println("Country:", h.TechInfo().Country)
|
|
fmt.Println("Email:", h.TechInfo().Email)
|
|
fmt.Println("Phone:", h.TechInfo().Phone)
|
|
fmt.Println("Fax:", h.TechInfo().Fax)
|
|
fmt.Println("====================")
|
|
fmt.Println("\nRaw:", h.RawData())
|
|
|
|
}
|
|
|
|
func TestWhois(t *testing.T) {
|
|
os.MkdirAll("./bin", 0755)
|
|
domainSuffix := []string{"com", "net", "org", "cn", "io", "me", "cc", "top", "xyz", "vip", "club", "site", "win", "bid",
|
|
"loan", "ek", "kim", "ren", "ltd", "link", "red", "pro", "info", "mobi", "name", "tv", "ws", "asia",
|
|
"biz", "gov", "edu", "mil", "int", "aero", "coop", "museum", "jobs", "travel", "xxx",
|
|
"ac", "ad", "ae", "af", "ag", "ai", "al", "am", "an", "ao", "aq", "ar", "as", "at", "au", "aw", "az",
|
|
"ba", "bb", "bd", "be", "bf", "bg", "bh", "bi", "bj", "bm", "bn", "bo", "br", "bs", "bt", "bv", "bw", "by", "bz",
|
|
"ca", "cc", "cd", "cf", "cg", "ch", "ci", "ck", "cl", "cm", "cn", "co", "cr", "cu", "cv", "cx", "cy", "cz",
|
|
"de", "dj", "dk", "dm", "do", "dz",
|
|
"ec", "ee", "eg", "eh", "er", "es", "et", "eu",
|
|
"fi", "fj", "fk", "fm", "fo", "fr",
|
|
"ga", "gb", "gd", "ge", "gf", "gg", "gh", "gi", "gl", "gm", "gn", "gp", "gq", "gr", "gs", "gt", "gu", "gw", "gy",
|
|
"hk", "hm", "hn", "hr", "ht", "hu",
|
|
"id", "ie", "il", "im", "in", "io", "iq", "ir", "is", "it",
|
|
"je", "jm", "jo", "jp",
|
|
"ke", "kg", "kh", "ki", "km", "kn", "kp", "kr", "kw", "ky", "kz",
|
|
"la", "lb", "lc", "li", "lk", "lr", "ls", "lt", "lu", "lv", "ly",
|
|
"ma", "mc", "md", "mg", "mh", "mk", "ml", "mm", "mn", "mo", "mp", "mq", "mr", "ms", "mt", "mu", "mv", "mw", "mx", "my", "mz",
|
|
"na", "nc", "ne", "nf", "ng", "ni", "nl", "no", "np", "nr", "nu", "nz",
|
|
"om",
|
|
"pa", "pe", "pf", "pg", "ph", "pk", "pl", "pm", "pn", "pr", "ps", "pt", "pw", "py",
|
|
"qa",
|
|
"re", "ro", "ru", "rw",
|
|
"sa", "sb", "sc", "sd", "se", "sg", "sh", "si", "sj", "sk", "sl", "sm", "sn", "so", "sr", "st", "sv", "sy", "sz",
|
|
"tc", "td", "tf", "tg", "th", "tj", "tk", "tl", "tm", "tn", "to", "tp", "tr", "tt", "tv", "tw", "tz",
|
|
"ua", "ug", "uk", "us", "uy", "uz",
|
|
"va", "vc", "ve", "vg", "vi", "vn", "vu",
|
|
"wf", "ws",
|
|
"ye", "yt", "yu",
|
|
"za", "zm", "zw"}
|
|
prefix := "nic."
|
|
c := NewClient()
|
|
for idx, suffix := range domainSuffix {
|
|
if idx < 50 {
|
|
continue
|
|
}
|
|
domain := prefix + suffix
|
|
if suffix == "cn" {
|
|
domain = "cnnic.cn"
|
|
}
|
|
if suffix == "int" {
|
|
domain = "who.int"
|
|
}
|
|
h, err := c.Whois(domain)
|
|
if err != nil {
|
|
fmt.Println(idx, domain, "net fail", err)
|
|
continue
|
|
}
|
|
os.WriteFile("./bin/"+domain+".txt", []byte(h.RawData()), 0644)
|
|
if !h.exists {
|
|
fmt.Println(idx, h.Domain(), "fail")
|
|
t.Fatal(domain, "not exists")
|
|
}
|
|
fmt.Println(idx, h.Domain(), "ok")
|
|
fmt.Println(h.ExpireDate(), h.RegisterDate())
|
|
if h.HasExpireDate() && h.ExpireDate().IsZero() {
|
|
t.Fatal("ExpireDate is zero")
|
|
}
|
|
if h.Domain() == "" {
|
|
t.Fatal("Domain is empty")
|
|
}
|
|
if h.HasRegisterDate() && h.RegisterDate().IsZero() {
|
|
t.Fatal("RegisterDate is zero")
|
|
}
|
|
if len(h.NsServers()) == 0 {
|
|
fmt.Println("NsServers is empty")
|
|
}
|
|
fmt.Println(h.Status())
|
|
}
|
|
}
|