Created
December 29, 2022 00:38
-
-
Save bontusss/d117e574307d79eb5e467cdd443dd475 to your computer and use it in GitHub Desktop.
available
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"fmt" | |
"log" | |
"net" | |
"os" | |
"strings" | |
"time" | |
) | |
func exists(domain string) (bool, error) { | |
const whoisServer string = "com.whois-servers.net" | |
conn, err := net.Dial("tcp", whoisServer+":43") | |
if err != nil { | |
return false, err | |
} | |
defer conn.Close() | |
conn.Write([]byte(domain + "\r\n")) | |
scanner := bufio.NewScanner(conn) | |
for scanner.Scan() { | |
if strings.Contains(strings.ToLower(scanner.Text()), "no match") { | |
return false, nil | |
} | |
} | |
return true, nil | |
} | |
var marks = map[bool]string{true: "✓", false: "✗"} | |
func main() { | |
s := bufio.NewScanner(os.Stdin) | |
for s.Scan() { | |
domain := s.Text() | |
fmt.Print(domain, " ") | |
exist, err := exists(domain) | |
if err != nil { | |
log.Fatalln(err) | |
} | |
fmt.Println(marks[!exist]) | |
time.Sleep(1 * time.Second) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment