Skip to content

Commit

Permalink
Use google.com for testing ability to resolve
Browse files Browse the repository at this point in the history
This was not working with user provided hosts as they are in the hosts file and providing false positives.
  • Loading branch information
rcaught committed Nov 4, 2019
1 parent 7d6d05c commit 02b63e3
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,20 @@ func parseOverrides(entries *hostsFileEntries, continueOnError bool) *hostsFileE
if maybeIP := *maybeIP(entry.ip); maybeIP != "" {
expandedEntries = append(expandedEntries, entry)
} else {
// NOTE: Try to resolve google.com, but this could be any domain to test
// if there is an Internet connection and hosts are resolvable.
//
// Can't use user provided domains, as they can already be in the
// hosts file and will provide a false positive.
_, googleErr := net.LookupIP("google.com")
ips, err := net.LookupIP(*entry.ip)

if err != nil {
fmt.Fprintf(os.Stderr, "Could not get IPs: %v\n", err)
if googleErr != nil || err != nil {
if continueOnError {
return nil
}

fmt.Fprintf(os.Stderr, "Could not get IPs: %v\n", err)
os.Exit(1)
}

Expand Down

0 comments on commit 02b63e3

Please sign in to comment.