Created
November 15, 2022 17:27
-
-
Save jimeh/37679cf392655a77a0e516ab12fce311 to your computer and use it in GitHub Desktop.
domain-finder.go
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 ( | |
"fmt" | |
"os" | |
"os/exec" | |
"strings" | |
"sync" | |
) | |
// Config - Horrible hack | |
const workers = 2 | |
const length = 2 | |
const tld = ".im" | |
func Generator(prefix string, length int, output chan string) { | |
alphabet := "abcdefghijklmnopqrstuvwxyz" | |
for _, r := range alphabet { | |
str := prefix + string(r) | |
if length == len(str) { | |
output <- str | |
} else { | |
Generator(str, length, output) | |
} | |
} | |
} | |
func Lookup(output chan string) { | |
for combo := range output { | |
domain := combo + tld | |
availableStr := domain + " is available for purchase" | |
response, err := Whois(domain) | |
if err != nil { | |
fmt.Fprintln(os.Stderr, "whois "+domain+" returned: ", err) | |
os.Exit(1) | |
} | |
if strings.Contains(response, availableStr) { | |
fmt.Println(domain + " - AVAILABLE") | |
} | |
} | |
} | |
func Whois(domain string) (string, error) { | |
var cmdOut []byte | |
var err error | |
cmdName := "whois" | |
cmdArgs := []string{domain} | |
if cmdOut, err = exec.Command(cmdName, cmdArgs...).Output(); err != nil { | |
return "", err | |
} | |
return string(cmdOut), nil | |
} | |
func main() { | |
output := make(chan string) | |
var wg sync.WaitGroup | |
go func() { | |
defer close(output) | |
Generator("", length, output) | |
}() | |
for i := 0; i < workers; i++ { | |
wg.Add(1) | |
go func() { | |
defer wg.Done() | |
Lookup(output) | |
}() | |
} | |
wg.Wait() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment