From 0d2575bc0ab604057b90fdab072a1f53ebf679cc Mon Sep 17 00:00:00 2001 From: Chandler Swift Date: Mon, 18 Oct 2021 22:36:35 -0500 Subject: [PATCH] Include DNS check and graceful error if no DNS record exists --- main.go | 11 +++++++++-- template.html | 4 ++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index c24a9a5..693af64 100644 --- a/main.go +++ b/main.go @@ -33,6 +33,7 @@ import ( "html/template" "io" "log" + "net" "net/http" "os" "time" @@ -51,8 +52,7 @@ type HatsSite struct { Registrant *whoisparser.Contact ScreenshotURL template.URL Title string - HTTPOpen bool - HTTPSOpen bool + Notes template.HTML } func getSites(largest int, wd selenium.WebDriver) (sites []HatsSite, err error) { @@ -82,6 +82,13 @@ func getSites(largest int, wd selenium.WebDriver) (sites []HatsSite, err error) hatsSite.Registrar = result.Registrar hatsSite.Registrant = result.Registrant + _, err = net.LookupHost(hatsSite.DomainName) + if err != nil { + hatsSite.Notes = template.HTML(fmt.Sprintf("DNS Error: %v", err.Error())) + sites = append(sites, hatsSite) + continue + } + // Get web page, take screenshot err = wd.Get(fmt.Sprintf("http://%v/", hatsSite.DomainName)) if err != nil { diff --git a/template.html b/template.html index d43705a..bc819dd 100644 --- a/template.html +++ b/template.html @@ -40,6 +40,10 @@
Title
{{.}}
{{end}} + {{with .Notes}} +
Notes
+
{{.}}
+ {{end}} {{if .ScreenshotURL}} screenshot of {{.DomainName}} as of {{.FetchTime.Format