package main // https://pkg.go.dev/github.com/tebeka/selenium#example-package // https://github.com/domainr/whois // https://golangexample.com/dns-lookup-using-go/ /* chandler@xenon ~/projects/hats-domains % for i in {1..50}; do [21:17:08] dig ${i}hats.com | grep -i nxdomain >/dev/null && echo ${i}hats.com is available done 5hats.com is available 16hats.com is available 26hats.com is available 28hats.com is available 30hats.com is available 35hats.com is available 36hats.com is available 37hats.com is available 41hats.com is available 43hats.com is available 44hats.com is available 46hats.com is available 48hats.com is available 49hats.com is available [1] chandler@xenon ~/projects/hats-domains % */ import ( "encoding/base64" "flag" "fmt" "html/template" "io" "log" "net/http" "os" "time" "github.com/likexian/whois" whoisparser "github.com/likexian/whois-parser" "github.com/tebeka/selenium" ) type HatsSite struct { DomainName string Available bool FetchTime time.Time DomainInfo *whoisparser.Domain Registrar *whoisparser.Contact Registrant *whoisparser.Contact ScreenshotURL template.URL Title string HTTPOpen bool HTTPSOpen bool } func getSites(largest int, wd selenium.WebDriver) (sites []HatsSite, err error) { // TODO: 1hat.com 0hats.com, hats.com; possibly onehat.com, twohats.com, etc for i := 2; i <= largest; i++ { hatsSite := HatsSite{ DomainName: fmt.Sprintf("%dhats.com", i), FetchTime: time.Now(), } log.Printf("Retrieving info for %v\n", hatsSite.DomainName) // Check if domain is registered query_result, err := whois.Whois(hatsSite.DomainName) if err != nil { return sites, err } result, err := whoisparser.Parse(query_result) if err == whoisparser.ErrNotFoundDomain { hatsSite.Available = true sites = append(sites, hatsSite) continue } else if err != nil { return sites, err } hatsSite.Available = false hatsSite.DomainInfo = result.Domain hatsSite.Registrar = result.Registrar hatsSite.Registrant = result.Registrant // Get web page, take screenshot err = wd.Get(fmt.Sprintf("http://%v/", hatsSite.DomainName)) if err != nil { return sites, err } hatsSite.Title, err = wd.Title() if err != nil { return sites, err } screenshot, err := wd.Screenshot() if err != nil { return sites, err } hatsSite.ScreenshotURL = template.URL(fmt.Sprintf("data:image/png;base64,%v", base64.StdEncoding.EncodeToString(screenshot))) sites = append(sites, hatsSite) } return sites, nil } func generateHTML(sites []HatsSite, w io.Writer) error { funcs := template.FuncMap{ "parseTime": func(s string) time.Time { time, _ := time.Parse(time.RFC3339, s); return time }, } tmpl, err := template.New("main").Funcs(funcs).Parse(`