forked from xellio/whois
-
Notifications
You must be signed in to change notification settings - Fork 0
/
icann.go
84 lines (64 loc) · 1.62 KB
/
icann.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
78
79
80
81
82
83
84
package whois
import (
"strings"
)
//
// parseICANNData parses whois output format of Internic.
//
func parseICANNData(in []byte) QueryResult {
result := NewQueryResult(in)
lastKey := ""
lastToken := []byte{}
currentToken := []byte{}
valueMode := false
currentRecord := make(map[string]string)
loop:
for i := 0; i < len(in); i++ {
tok := in[i]
switch {
case (tok == '\n'):
key := normalizeKey(string(lastToken))
value := normalizeValue(string(currentToken))
if strings.Index(key, "Registry ") == 0 && len(currentRecord) > 0 && len(value) == 0 {
zoneType := RecordTypeOther
switch key[9:] {
case "Domain ID":
zoneType = RecordTypeDomain
case "Registrant ID":
zoneType = RecordTypeOwner
case "Admin ID":
zoneType = RecordTypeAdminC
case "Tech ID":
zoneType = RecordTypeTechC
}
result.records = append(result.Records(), NewQueryRecord(currentRecord, zoneType))
currentRecord = make(map[string]string)
}
if key != "" && value != "" {
if lastKey == key {
currentRecord[key] += "\n" + value
} else {
currentRecord[key] = value
}
lastKey = key
}
valueMode = false
lastToken = []byte{}
currentToken = []byte{}
continue
case (tok == ':' && !valueMode):
valueMode = true
lastToken = currentToken
currentToken = []byte{}
continue
case (tok == '>' && len(in) > i+2 && in[i+1] == '>' && in[i+2] == '>'):
break loop
default:
currentToken = append(currentToken, tok)
}
}
if len(currentRecord) > 0 {
result.records = append(result.Records(), NewQueryRecord(currentRecord, 0))
}
return result
}