From afc4f62a7821dcc2b79e58f0f5e9380e3236537a Mon Sep 17 00:00:00 2001 From: yoneyan Date: Sun, 29 Aug 2021 03:45:30 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[fix]=20count=E3=81=AE=E5=80=A4=E3=81=8C?= =?UTF-8?q?=E9=96=93=E9=81=95=E3=81=88=E3=81=A6=E3=81=84=E3=81=9F=E3=81=AE?= =?UTF-8?q?=E3=81=A7=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jpnic.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jpnic.go b/jpnic.go index 4d50959..85d266b 100644 --- a/jpnic.go +++ b/jpnic.go @@ -590,7 +590,7 @@ func (c *Config) GetIPUser(userURL string) (InfoDetailLong, error) { }) // 自所属ではないとき、struct数が13個になる // この場合は、並び替えを実施する - if count == 12 { + if count == 11 { info = InfoDetailLong{} info.IPAddress = infoShort.IPAddress info.Ryakusho = infoShort.Ryakusho From f53c23dabc252b10bc3c535f26bcb96cb6dadc1f Mon Sep 17 00:00:00 2001 From: yoneyan Date: Sun, 29 Aug 2021 03:57:24 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[fix]=20=E5=80=A4=E3=81=8C=E6=AD=A3?= =?UTF-8?q?=E3=81=97=E3=81=8F=E5=8F=96=E5=BE=97=E3=81=A7=E3=81=8D=E3=81=AA?= =?UTF-8?q?=E3=81=84=E5=95=8F=E9=A1=8C=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jpnic.go | 97 ++++++++++++++------------------------------------- jpnic_test.go | 20 +++++------ 2 files changed, 34 insertions(+), 83 deletions(-) diff --git a/jpnic.go b/jpnic.go index 85d266b..e0e5b67 100644 --- a/jpnic.go +++ b/jpnic.go @@ -10,6 +10,7 @@ import ( "golang.org/x/text/encoding/japanese" "golang.org/x/text/transform" "io/ioutil" + "log" "net/http" "net/http/cookiejar" "net/url" @@ -420,7 +421,6 @@ func (c *Config) GetAllIPv6(searchStr string) ([]InfoIPv6, error) { func (c *Config) GetIPUser(userURL string) (InfoDetailLong, error) { var info InfoDetailLong - var infoShort InfoDetailShort sessionID, err := randomStr() if err != nil { @@ -498,8 +498,6 @@ func (c *Config) GetIPUser(userURL string) (InfoDetailLong, error) { return info, err } - count := 0 - doc.Find("table").Each(func(_ int, tableHtml1 *goquery.Selection) { tableHtml1.Find("tr").Each(func(_ int, rowHtml1 *goquery.Selection) { rowHtml1.Find("td").Each(func(_ int, tableCell1 *goquery.Selection) { @@ -511,103 +509,60 @@ func (c *Config) GetIPUser(userURL string) (InfoDetailLong, error) { rowHtml3.Find("td").Each(func(_ int, tableCell3 *goquery.Selection) { tableCell3.Find("table").Each(func(_ int, tableHtml4 *goquery.Selection) { tableHtml4.Find("tr").Each(func(_ int, rowHtml4 *goquery.Selection) { + var title string rowHtml4.Find("td").Each(func(index int, tableCell4 *goquery.Selection) { dataStr := strings.TrimSpace(tableCell4.Text()) + log.Println(dataStr) if index == 1 { - switch count { - case 0: + switch title { + case "IPネットワークアドレス": info.IPAddress = dataStr - //short - infoShort.IPAddress = dataStr - case 1: + case "資源管理者略称": info.Ryakusho = dataStr - //short - infoShort.Ryakusho = dataStr - case 2: + case "アドレス種別": info.Type = dataStr - //short - infoShort.Type = dataStr - case 3: + case "インフラ・ユーザ区分": info.InfraUserKind = dataStr - //short - infoShort.InfraUserKind = dataStr - case 4: + case "ネットワーク名": info.NetworkName = dataStr - //short - infoShort.NetworkName = dataStr - case 5: + case "組織名": info.Org = dataStr - //short - infoShort.Org = dataStr - case 6: + case "Organization": info.OrgEn = dataStr - //short - infoShort.OrgEn = dataStr - case 7: + case "郵便番号": info.PostCode = dataStr - //short - infoShort.AdminJPNICHandle = dataStr - infoShort.AdminJPNICHandleLink, _ = tableCell4.Find("a").Attr("href") - case 8: + case "住所": info.Address = dataStr - //short - infoShort.TechJPNICHandle = dataStr - infoShort.TechJPNICHandleLink, _ = tableCell4.Find("a").Attr("href") - case 9: + case "Address": info.AddressEn = dataStr - //short - infoShort.AssignDate = dataStr - case 10: + case "管理者連絡窓口": info.AdminJPNICHandle = dataStr info.AdminJPNICHandleLink, _ = tableCell4.Find("a").Attr("href") - //short - infoShort.ReturnDate = dataStr - case 11: + case "技術連絡担当者": info.TechJPNICHandle = dataStr info.TechJPNICHandleLink, _ = tableCell4.Find("a").Attr("href") - //short - infoShort.UpdateDate = dataStr - case 12: + case "ネームサーバ": info.NameServer = dataStr - case 13: + case "DSレコード": info.DSRecord = dataStr - case 14: + case "通知アドレス": info.NotifyAddress = dataStr - case 15: + case "審議番号": info.DeliNo = dataStr - case 16: + case "受付番号": info.RecepNo = dataStr - case 17: + case "割当年月日": info.AssignDate = dataStr - case 18: + case "返却年月日": info.ReturnDate = dataStr - case 19: + case "最終更新": info.UpdateDate = dataStr } - count++ + } else { + title = dataStr } }) }) - // 自所属ではないとき、struct数が13個になる - // この場合は、並び替えを実施する - if count == 11 { - info = InfoDetailLong{} - info.IPAddress = infoShort.IPAddress - info.Ryakusho = infoShort.Ryakusho - info.Type = infoShort.Type - info.InfraUserKind = infoShort.InfraUserKind - info.NetworkName = infoShort.NetworkName - info.Org = infoShort.Org - info.OrgEn = infoShort.OrgEn - info.AdminJPNICHandle = infoShort.AdminJPNICHandle - info.AdminJPNICHandleLink = infoShort.AdminJPNICHandleLink - info.TechJPNICHandle = infoShort.TechJPNICHandle - info.TechJPNICHandleLink = infoShort.TechJPNICHandleLink - info.NameServer = infoShort.NameServer - info.AssignDate = infoShort.AssignDate - info.ReturnDate = infoShort.ReturnDate - info.UpdateDate = infoShort.UpdateDate - } }) }) }) diff --git a/jpnic_test.go b/jpnic_test.go index f32276f..34a2c89 100644 --- a/jpnic_test.go +++ b/jpnic_test.go @@ -7,18 +7,16 @@ import ( var caFilePath = "/home/yonedayuto/Documents/HomeNOC/cert/rootcacert_r3.cer" // HomeNOC -//var certFilePathV4 = "/home/yonedayuto/Documents/HomeNOC/cert/v4-cert.pem" -//var keyFilePathV4 = "/home/yonedayuto/Documents/HomeNOC/cert/v4-prvkey.pem" -//var certFilePathV6 = "/home/yonedayuto/Documents/HomeNOC/cert/v6-cert.pem" -//var keyFilePathV6 = "/home/yonedayuto/Documents/HomeNOC/cert/v6-prvkey.pem" +var certFilePathV4 = "/home/yonedayuto/Documents/HomeNOC/cert/v4-cert.pem" +var keyFilePathV4 = "/home/yonedayuto/Documents/HomeNOC/cert/v4-prvkey.pem" +var certFilePathV6 = "/home/yonedayuto/Documents/HomeNOC/cert/v6-cert.pem" +var keyFilePathV6 = "/home/yonedayuto/Documents/HomeNOC/cert/v6-prvkey.pem" // doornoc -var certFilePathV4 = "/home/yonedayuto/Documents/doornoc/cert/v4-cert.pem" -var keyFilePathV4 = "/home/yonedayuto/Documents/doornoc/cert/v4-prvkey.pem" -var certFilePathV6 = "/home/yonedayuto/Documents/doornoc/cert/v6-cert.pem" -var keyFilePathV6 = "/home/yonedayuto/Documents/doornoc/cert/v6-prvkey.pem" - -//var caFilePath = "/home/yonedayuto/Documents/doornoc/cert/rootcacert_r3.cer" +//var certFilePathV4 = "/home/yonedayuto/Documents/doornoc/cert/v4-cert.pem" +//var keyFilePathV4 = "/home/yonedayuto/Documents/doornoc/cert/v4-prvkey.pem" +//var certFilePathV6 = "/home/yonedayuto/Documents/doornoc/cert/v6-cert.pem" +//var keyFilePathV6 = "/home/yonedayuto/Documents/doornoc/cert/v6-prvkey.pem" // Search String (HOMENOC/DOORNOC) var searchStr = "HOMENOC" @@ -84,8 +82,6 @@ func TestGetIPv6User(t *testing.T) { CAFilePath: caFilePath, } - t.Log(con) - data, err := con.GetIPUser(v6UserURL) if err != nil { t.Fatal(err)