-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse.go
More file actions
41 lines (29 loc) · 909 Bytes
/
parse.go
File metadata and controls
41 lines (29 loc) · 909 Bytes
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
package main
import (
"errors"
"fmt"
"strings"
"dohunt/pkg/dns"
"github.com/valyala/fasthttp"
)
func parseDomain(client *fasthttp.Client, fullDomain string) (sld string, tld string, domain string, err error) {
if !strings.Contains(fullDomain, ".") {
return "", "", "", errors.New("invalid domain")
}
x := strings.Split(strings.ToLower(fullDomain), ".")
if len(x) >= 3 {
ownedByRegistry, err := dns.IsSLDOwnedByRegistry(client, x[len(x)-2]+"."+x[len(x)-1])
if err != nil {
return "", "", "", err
}
if ownedByRegistry {
return x[len(x)-2] + "." + x[len(x)-1], x[len(x)-1], x[len(x)-3] + "." + x[len(x)-2] + "." + x[len(x)-1], nil
} else {
return x[len(x)-1], x[len(x)-1], x[len(x)-2] + "." + x[len(x)-1], nil
}
} else if len(x) == 2 {
return x[len(x)-1], x[len(x)-1], fullDomain, nil
} else {
return "", "", "", fmt.Errorf("invalid domain %v", fullDomain)
}
}