-
Notifications
You must be signed in to change notification settings - Fork 0
/
jpnic_detail.go
215 lines (187 loc) · 4.76 KB
/
jpnic_detail.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
package jpnic
import (
"github.com/PuerkitoBio/goquery"
"log"
"net/http"
"strings"
)
func getInfoDetail(client *http.Client, userURL string) (InfoDetail, error) {
var info InfoDetail
r := request{
Client: client,
URL: baseURL + userURL,
Body: "",
UserAgent: userAgent,
ContentType: contentType,
}
resp, err := r.get()
if err != nil {
log.Println(err)
return info, err
}
respBody, _, err := readShiftJIS(resp.Body)
if err != nil {
return info, err
}
doc, err := goquery.NewDocumentFromReader(strings.NewReader(respBody))
if err != nil {
return info, err
}
var title string
isTitle := true
doc.Find("table").Children().Find("table").Children().Find("table").Children().Find("table").Children().Find("td").Each(func(_ int, tableHtml1 *goquery.Selection) {
dataStr := strings.TrimSpace(tableHtml1.Text())
if isTitle {
title = dataStr
}
switch title {
case "IPネットワークアドレス":
info.IPAddress = dataStr
case "資源管理者略称":
info.Ryakusho = dataStr
case "アドレス種別":
info.Type = dataStr
case "インフラ・ユーザ区分":
info.InfraUserKind = dataStr
case "ネットワーク名":
info.NetworkName = dataStr
case "組織名":
info.Org = dataStr
case "Organization":
info.OrgEn = dataStr
case "郵便番号":
info.PostCode = dataStr
case "住所":
info.Address = dataStr
case "Address":
info.AddressEn = dataStr
case "管理者連絡窓口":
info.AdminJPNICHandle = dataStr
info.AdminJPNICHandleLink, _ = tableHtml1.Find("a").Attr("href")
case "技術連絡担当者":
info.TechJPNICHandle = dataStr
info.TechJPNICHandleLink, _ = tableHtml1.Find("a").Attr("href")
case "ネームサーバ":
info.NameServer = dataStr
case "DSレコード":
info.DSRecord = dataStr
case "通知アドレス":
info.NotifyAddress = dataStr
case "審議番号":
info.DeliNo = dataStr
case "受付番号":
info.RecepNo = dataStr
case "割当年月日":
info.AssignDate = dataStr
case "返却年月日":
info.ReturnDate = dataStr
case "最終更新":
info.UpdateDate = dataStr
}
isTitle = !isTitle
})
return info, err
}
func getJPNICHandle(client *http.Client, handleURL string) (JPNICHandleDetail, error) {
var info JPNICHandleDetail
r := request{
Client: client,
URL: baseURL + "/jpnic/" + handleURL,
Body: "",
UserAgent: userAgent,
ContentType: contentType,
}
resp, err := r.get()
if err != nil {
return info, err
}
resBody, _, err := readShiftJIS(resp.Body)
if err != nil {
return info, err
}
doc, err := goquery.NewDocumentFromReader(strings.NewReader(resBody))
if err != nil {
return info, err
}
var title string
isTitle := true
doc.Find("table").Children().Find("table").Children().Find("table").Children().Find("td").Each(func(_ int, tableHtml1 *goquery.Selection) {
dataStr := strings.TrimSpace(tableHtml1.Text())
if isTitle {
title = dataStr
}
switch title {
case "グループハンドル":
info.IsJPNICHandle = false
info.JPNICHandle = dataStr
case "グループ名":
info.Name = dataStr
case "Group Name":
info.NameEn = dataStr
case "JPNICハンドル":
info.IsJPNICHandle = true
info.JPNICHandle = dataStr
case "氏名":
info.Name = dataStr
case "Last, First":
info.NameEn = dataStr
case "電子メール":
info.Email = dataStr
case "電子メイル": // JPNIC側の表記ゆれのため
info.Email = dataStr
case "組織名":
info.Org = dataStr
case "Organization":
info.OrgEn = dataStr
case "部署":
info.Division = dataStr
case "Division":
info.DivisionEn = dataStr
case "肩書":
info.Title = dataStr
case "Title":
info.TitleEn = dataStr
case "電話番号":
info.Tel = dataStr
case "Fax番号":
info.Fax = dataStr
case "FAX番号": // JPNIC側の表記ゆれのため
info.Fax = dataStr
case "通知アドレス":
info.NotifyAddress = dataStr
case "最終更新":
info.UpdateDate = dataStr
}
isTitle = !isTitle
})
return info, err
}
func getRecepDetail(client *http.Client, recepURL string) (string, error) {
r := request{
Client: client,
URL: baseURL + recepURL,
UserAgent: userAgent,
ContentType: contentType,
}
resp, err := r.get()
if err != nil {
return "", err
}
defer resp.Body.Close()
body, _, err := readShiftJIS(resp.Body)
if err != nil {
return "", err
}
doc, err := goquery.NewDocumentFromReader(strings.NewReader(body))
if err != nil {
return "", err
}
var info string
doc.Find("table").Children().Find("table").Children().Find("td").Each(func(index int, tableHtml1 *goquery.Selection) {
dataStr := strings.TrimSpace(tableHtml1.Text())
if dataStr != "" {
info = "\n" + dataStr
}
})
return info, nil
}