Skip to content

Instantly share code, notes, and snippets.

@mahdyar
Last active January 30, 2021 21:21
Show Gist options
  • Save mahdyar/fbbb8c925263dd22999994bfa69c2c89 to your computer and use it in GitHub Desktop.
Save mahdyar/fbbb8c925263dd22999994bfa69c2c89 to your computer and use it in GitHub Desktop.
Whois lookup script written in Golang for .ir domains
package main
import (
"fmt"
"net"
)
/*************************************************************************
Author: Mahdyar
Github: https://github.com/mahdyar
*************************************************************************/
func whois(domainName string) string {
server := "whois.nic.ir"
conn, err := net.Dial("tcp", server+":43")
if err != nil {
fmt.Println("Err!")
}
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("mahdyar.ir")
fmt.Println(result)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment