goutils/cmd/host/main.go

42 lines
551 B
Go
Raw Normal View History

2024-04-26 21:15:08 +00:00
package main
import (
"flag"
"fmt"
"log"
"net"
)
func lookupHost(host string) error {
cname, err := net.LookupCNAME(host)
if err != nil {
return err
}
if cname != host {
fmt.Printf("%s is a CNAME for %s\n", host, cname)
host = cname
}
addrs, err := net.LookupHost(host)
if err != nil {
return err
}
for _, addr := range addrs {
fmt.Printf("\t%s\n", addr)
}
return nil
}
func main() {
flag.Parse()
for _, arg := range flag.Args() {
if err := lookupHost(arg); err != nil {
2024-05-20 03:51:35 +00:00
log.Printf("%s: %s", arg, err)
2024-04-26 21:15:08 +00:00
}
}
}