-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.go
77 lines (65 loc) · 1.56 KB
/
app.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"bufio"
"fmt"
"os"
"strings"
"github.com/fatih/color"
"github.com/likexian/whois"
)
func main() {
// Open domains file
file, err := os.Open("domains.txt")
if err != nil {
fmt.Println("Failed to open file: ", err)
return
}
defer file.Close()
// Create output files
positiveFile, err := os.Create("available.txt")
if err != nil {
fmt.Println("Failed to create positive output file: ", err)
return
}
defer positiveFile.Close()
negativeFile, err := os.Create("taken.txt")
if err != nil {
fmt.Println("Failed to create negative output file: ", err)
return
}
defer negativeFile.Close()
// Scan domains file line by line
scanner := bufio.NewScanner(file)
for scanner.Scan() {
domain := strings.TrimSpace(scanner.Text())
// Skip empty lines
if domain == "" {
continue
}
// Check if domain is registered
if isRegistered(domain) {
fmt.Fprintln(negativeFile, domain)
} else {
fmt.Fprintln(positiveFile, domain)
// Print unregistered domains to console in green color
green := color.New(color.FgGreen).SprintFunc()
fmt.Printf("Unregistered domain: %s\n", green(domain))
}
}
if err := scanner.Err(); err != nil {
fmt.Println("Failed to read file: ", err)
return
}
fmt.Println("Done!")
}
// Check if domain is registered
func isRegistered(domain string) bool {
raw, err := whois.Whois(domain)
if err != nil {
return false
}
if strings.Contains(raw, "No match for domain") || strings.Contains(raw, "NOT FOUND") || strings.Contains(raw, "Status: AVAILABLE") {
return false
}
return true
}