diff options
| author | Jeff Carr <[email protected]> | 2025-09-22 18:54:37 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-09-22 18:54:37 -0500 |
| commit | c62c11341dd879e54289e239d1249ff8e4bc9040 (patch) | |
| tree | bbdfa378d9104dfa4a1965093f39f19878aaaa89 /whois.go | |
| parent | 6a205dfa4e3f217e3317509911ddc812a8ef49f6 (diff) | |
Diffstat (limited to 'whois.go')
| -rw-r--r-- | whois.go | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/whois.go b/whois.go new file mode 100644 index 0000000..5299057 --- /dev/null +++ b/whois.go @@ -0,0 +1,47 @@ +package hostname + +import ( + "io" + "net" +) + +// GetWhois performs a raw whois query for a given domain. +// Note: This does not recursively find the right server; it uses a known one. +func GetWhois(domain, server string) (string, error) { + // Connect to the whois server on port 43 + conn, err := net.Dial("tcp", net.JoinHostPort(server, "43")) + if err != nil { + return "", err + } + defer conn.Close() + + // Send the domain query + _, err = conn.Write([]byte(domain + "\r\n")) + if err != nil { + return "", err + } + + // Read the entire response + result, err := io.ReadAll(conn) + if err != nil { + return "", err + } + + return string(result), nil +} + +/* +func main() { +// We have to know the server for .com domains +const whoisServer = "whois.verisign-grs.com" + domain :="google.com" + + whoisData, err := GetWhois(domain, whoisServer) +if err != nil { + log.Fatal"Error getting whois info: %v", err) + } + + fmt.Println(whoisData) +} + +*/ |
