Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
topscoder committed May 31, 2023
0 parents commit 3070704
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# domainer
45 changes: 45 additions & 0 deletions domainer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package main

import (
"bufio"
"fmt"
"os"
"strings"
)

func extractRootDomain(domain string) string {
parts := strings.Split(domain, ".")
if len(parts) < 2 {
return "none"
}
return strings.Join(parts[len(parts)-2:], ".")
}

func main() {
stat, _ := os.Stdin.Stat()
if (stat.Mode() & os.ModeCharDevice) != 0 {
fmt.Fprintln(os.Stderr, "Please provide domains via stdin.")
os.Exit(1)
}

scanner := bufio.NewScanner(os.Stdin)
seenDomains := make(map[string]bool)

for scanner.Scan() {
domain := scanner.Text()
rootDomain := extractRootDomain(domain)
if rootDomain != "none" {
seenDomains[rootDomain] = true
}
}

if scanner.Err() != nil {
fmt.Fprintln(os.Stderr, "Error reading input:", scanner.Err())
os.Exit(1)
}

for domain := range seenDomains {
fmt.Println(domain)
}
}

3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/topscoder/domainer

go 1.20

0 comments on commit 3070704

Please sign in to comment.