Include DNS check and graceful error if no DNS record exists

This commit is contained in:
Chandler Swift 2021-10-18 22:36:35 -05:00
parent 123bd7d62a
commit 0d2575bc0a
Signed by: chandlerswift
GPG key ID: A851D929D52FB93F
2 changed files with 13 additions and 2 deletions

11
main.go
View file

@ -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: <code>%v</code>", err.Error()))
sites = append(sites, hatsSite)
continue
}
// Get web page, take screenshot
err = wd.Get(fmt.Sprintf("http://%v/", hatsSite.DomainName))
if err != nil {

View file

@ -40,6 +40,10 @@
<dt>Title</dt>
<dd>{{.}}</dd>
{{end}}
{{with .Notes}}
<dt>Notes</dt>
<dd>{{.}}</dd>
{{end}}
</dl>
{{if .ScreenshotURL}}
<img src="{{.ScreenshotURL}}" alt="screenshot of {{.DomainName}} as of {{.FetchTime.Format "Mon Jan 2 15:04:05 -0700 MST 2006" }}">