Skip to content

Commit

Permalink
Count TLDs
Browse files Browse the repository at this point in the history
  • Loading branch information
superboum committed Dec 21, 2021
1 parent 4c68205 commit 9064861
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions internet/dns/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package main

import(
"fmt"
"io"
"log"
"bufio"
"strings"
"net/http"
)

func main() {
url := "https://data.iana.org/TLD/tlds-alpha-by-domain.txt"


resp, err := http.Get(url)
if err != nil {
log.Fatal(err)
}

tld_count := 0
reader := bufio.NewReader(resp.Body)
for {
buf, err := reader.ReadBytes('\n')
if err == io.EOF {
break
} else if err != nil {
log.Fatal(err)
}
line := string(buf)
if strings.HasPrefix(line, "#") {
continue
}

fmt.Print(line)
tld_count += 1
}
fmt.Printf("count: %d TLDs\n", tld_count)
}

0 comments on commit 9064861

Please sign in to comment.