-
Notifications
You must be signed in to change notification settings - Fork 3
/
domain_whois.go
48 lines (37 loc) · 1.06 KB
/
domain_whois.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
package main
import (
"time"
"github.com/araddon/dateparse"
whois "github.com/likexian/whois"
whoisparser "github.com/likexian/whois-parser"
)
// DomainWhois will return structured whois data
func DomainWhois(domain Domain) (WhoisData, error) {
t := time.Now()
whoisRaw, e1 := whois.Whois(domain.Unicode)
if e1 != nil {
return WhoisData{}, e1
}
whoisInfo, e2 := whoisparser.Parse(whoisRaw)
if e2 != nil {
return WhoisData{}, e2
}
createdDate, e := dateparse.ParseLocal(whoisInfo.Domain.CreatedDate)
if e == nil {
whoisInfo.Domain.CreatedDate = createdDate.Format(time.RFC3339)
}
expirationDate, e := dateparse.ParseLocal(whoisInfo.Domain.ExpirationDate)
if e == nil {
whoisInfo.Domain.ExpirationDate = expirationDate.Format(time.RFC3339)
}
updatedDate, e := dateparse.ParseLocal(whoisInfo.Domain.UpdatedDate)
if e == nil {
whoisInfo.Domain.UpdatedDate = updatedDate.Format(time.RFC3339)
}
result := WhoisData{}
result.Date = t.Format(time.RFC3339)
result.WhoIs = whoisInfo
result.Domain = domain
result.Raw = whoisRaw
return result, nil
}