Skip to content

Commit

Permalink
Refs #74, select the first domain name, that ends with dot.
Browse files Browse the repository at this point in the history
  • Loading branch information
tvrzna committed Aug 11, 2022
1 parent b4a70df commit b1936cf
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,14 @@ func getDnsDomainName() string {
domain = canonname[strings.Index(canonname, ".")+1 : len(canonname)]
}
if domain == "" {
if ipaddresses, err := net.LookupHost(host); err == nil && len(ipaddresses) > 0 {
if domains, err := net.LookupAddr(ipaddresses[0]); err == nil {
domain = domains[0][strings.Index(domains[0], ".")+1 : len(domains[0])]
if ip, err := net.LookupHost(host); err == nil && len(ip) > 0 {
if domains, err := net.LookupAddr(ip[0]); err == nil {
for _, d := range domains {
if d[len(d)-1:] == "." {
domain = d[strings.Index(d, ".")+1 : len(d)]
break
}
}
}
}
}
Expand Down

0 comments on commit b1936cf

Please sign in to comment.