blob: 0e313b18bd2ab7caf1f3d82b95940588902d6b02 [file] [log] [blame]
package whois
// Support for the WHOIS protocol.
import (
"context"
"fmt"
"io/ioutil"
"net"
"strings"
)
// Query returns a semi-raw response from a WHOIS server for a given query.
// We only convert \r\n to \n, and then do no other transformation to the data.
func Query(ctx context.Context, server string, query string) (string, error) {
var d net.Dialer
conn, err := d.DialContext(ctx, "tcp", server)
if err != nil {
return "", fmt.Errorf("while dialing %q: %v", server, err)
}
defer conn.Close()
fmt.Fprintf(conn, "%s\r\n", query)
data, err := ioutil.ReadAll(conn)
if err != nil {
return "", fmt.Errorf("while receiving data from %q: %v", server, err)
}
return strings.ReplaceAll(string(data), "\r", ""), nil
}