package main import ( "fmt"; "flag"; "net"; "os"; "strings"; "bytes"; ) func main() { var ( host = "whois.nic.fr"; // Currently only .FR domain names port = "43"; remote = host + ":" + port; query string; rsp = make([]byte, 1024); ) if flag.NArg() != 1 { fmt.Printf("Usage: whois query\n"); os.Exit(1); } query = flag.Arg(0); con, error := net.Dial("tcp", "", remote); if error != nil { fmt.Printf("Cannot connect: %s\n", error); os.Exit(1); } defer con.Close(); out, error := con.Write(strings.Bytes(query + "\r\n")); if error != nil { fmt.Printf("Error sending data: %s, out: %d\n", error, out); os.Exit(2); } fmt.Printf("Connection with %s OK\nResponse is:\n", remote); for over := false; !over; { in, error := con.Read(rsp); if error != nil { if error == os.EOF { over = true } else { fmt.Printf("Error reading data: %s, in: %d\n", error, in); os.Exit(2); } } else { if in == 0 { over = true } else { buf := bytes.NewBuffer(rsp[1:in]); fmt.Printf("%s", buf.String()); } } } }