summaryrefslogtreecommitdiff
path: root/whois.go
diff options
context:
space:
mode:
Diffstat (limited to 'whois.go')
-rw-r--r--whois.go47
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)
+}
+
+*/