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
+5k Golang : Check if a word is countable or not
+7.6k Golang : get the current working directory of a running program
+6.8k Nginx : Password protect a directory/folder
+36.2k Golang : Save image to PNG, JPEG or GIF format.
+12.2k Golang : How to check if a string starts or ends with certain characters or words?
+37.6k Golang : Comparing date or timestamp
+9.8k Golang : Get current, epoch time and display by year, month and day
+10.3k Golang : Simple Jawi(Yawi) to Rumi(Latin/Romanize) converter
+6k Golang : Debug with Godebug
+87.3k Golang : How to convert character to ASCII and back
+10.4k Golang : Meaning of omitempty in struct's field tag
+36.4k Golang : Validate IP address