Golang : Whois examples
Whois a network utility to find out "who is" the owner behind a domain name. Some owners will display all the private information such as personal home address, mobile/cell phone numbers and while some will choose to protect their privacy. Here are couple of examples on how to implement whois
query in Golang.
Example 1:
package main
import (
"fmt"
"net"
)
func whois(domainName, server string) string {
conn, err := net.Dial("tcp", server+":43")
if err != nil {
fmt.Println("Error")
}
defer conn.Close()
conn.Write([]byte(domainName + "\r\n"))
buf := make([]byte, 1024)
result := []byte{}
for {
numBytes, err := conn.Read(buf)
sbuf := buf[0:numBytes]
result = append(result, sbuf...)
if err != nil {
break
}
}
return string(result)
}
func main() {
result := whois("socketloop.com", "com.whois-servers.net")
fmt.Println(result)
}
Example 2:
package main
import (
"fmt"
"github.com/likexian/whois-go"
)
func main() {
result, err := whois.Whois("socketloop.com")
if err != nil {
fmt.Println(err)
}
fmt.Println(result)
}
References :
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+24.4k Golang : How to print rune, unicode, utf-8 and non-ASCII CJK(Chinese/Japanese/Korean) characters?
+11.1k Golang : Calculate Relative Strength Index(RSI) example
+14k Golang : Fix image: unknown format error
+15.4k Golang : Force download file example
+25.2k Golang : Convert uint value to string type
+10.3k Swift : Convert (cast) String to Integer
+8.1k Android Studio : Rating bar example
+6.5k Golang : Convert an executable file into []byte example
+6.1k Linux/Unix : Commands that you need to be careful about
+22k Golang : How to run Golang application such as web server in the background or as daemon?
+7.9k Golang : What fmt.Println() can do and println() cannot do
+11.8k Golang : Determine if time variables have same calendar day