-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoc.go
102 lines (84 loc) · 1.98 KB
/
poc.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package arin
import (
"fmt"
"strings"
)
type Contact struct {
Name string
Handle string
Company string
Address1 string
Address2 string
City string
StateProv string
PostalCode string
Country string
Registered string
Updated string
Phone string
Email string
}
func (c *Contact) addressString() string {
var s []string
s = append(s, c.Address1)
if c.Address2 != "" {
s = append(s, c.Address2)
}
s = append(s, fmt.Sprintf("%s, %s %s", c.City, c.StateProv, c.PostalCode))
s = append(s, c.Country)
return strings.Join(s, "\n")
}
func (c *Contact) String() string {
var s []string
s = append(s, "Whois Contact Record")
s = append(s, "====================")
s = append(s, fmt.Sprintf("%s (%s)", c.Name, c.Handle))
s = append(s, c.addressString())
s = append(s, c.Phone)
s = append(s, c.Email)
s = append(s, fmt.Sprintf("%s (%s)", c.Registered, c.Updated))
return strings.Join(s, "\n")
}
func (c *Contact) Equal(c2 *Contact) bool {
return c.Name == c2.Name &&
c.Handle == c2.Handle &&
c.Company == c2.Company &&
c.Address1 == c2.Address1 &&
c.Address2 == c2.Address2 &&
c.City == c2.City &&
c.StateProv == c2.StateProv &&
c.PostalCode == c2.PostalCode &&
c.Country == c2.Country &&
c.Registered == c2.Registered &&
c.Updated == c2.Updated &&
c.Phone == c2.Phone &&
c.Email == c2.Email
}
func NewContact(handle string) *Contact {
var c = new(Contact)
record := makeRequest("poc", handle)
if record == "" {
return c
}
rec := parseRecord(record)
addr := strings.Split(rec["Address"], "\n")
c.Name = rec["Name"]
c.Handle = rec["Handle"]
c.Company = rec["Company"]
switch len(addr) {
case 2:
c.Address1 = addr[0]
c.Address2 = addr[1]
default:
c.Address1 = addr[0]
}
c.City = rec["City"]
c.StateProv = rec["StateProv"]
c.PostalCode = rec["PostalCode"]
c.Country = rec["Country"]
c.Registered = rec["RegDate"]
c.Updated = rec["Updated"]
c.Phone = rec["Phone"]
c.Email = rec["Email"]
return c
}