Skip to content

Commit

Permalink
Merge pull request #79 from mdn1023/master
Browse files Browse the repository at this point in the history
(feature): parse .AT domains
  • Loading branch information
likexian authored Mar 8, 2024
2 parents f5d7858 + 598518c commit 6b9845e
Show file tree
Hide file tree
Showing 18 changed files with 563 additions and 9 deletions.
18 changes: 9 additions & 9 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ func TestParse(t *testing.T) {
assert.Equal(t, whoisInfo.Domain.Punycode, domain)
assert.Equal(t, whoisInfo.Domain.Extension, extension)

if !assert.IsContains([]string{"", "aq", "br", "ch", "de", "edu", "eu", "fr", "gov", "hk",
if !assert.IsContains([]string{"", "at", "aq", "br", "ch", "de", "edu", "eu", "fr", "gov", "hk",
"hm", "int", "it", "jp", "kr", "kz", "mo", "nl", "nz", "pl", "pm", "re", "ro", "ru", "su", "tf", "ee",
"tk", "travel", "tv", "tw", "uk", "wf", "yt", "ir", "fi", "rs", "dk", "by", "ua",
"xn--mgba3a4f16a", "xn--p1ai", "se", "nu", "hu"}, extension) {
assert.NotZero(t, whoisInfo.Domain.ID)
}

if !assert.IsContains([]string{"ch", "edu", "eu", "int", "kr", "mo", "tw", "ir", "pl", "tk", "by",
if !assert.IsContains([]string{"at", "ch", "edu", "eu", "int", "kr", "mo", "tw", "ir", "pl", "tk", "by",
"xn--mgba3a4f16a", "hu"}, extension) {
assert.NotZero(t, whoisInfo.Domain.Status)
}
Expand All @@ -128,7 +128,7 @@ func TestParse(t *testing.T) {
assert.False(t, whoisInfo.Domain.DNSSec)
}

if !assert.IsContains([]string{"aero", "aq", "asia", "berlin", "biz", "br", "ch", "cn",
if !assert.IsContains([]string{"aero", "at", "aq", "asia", "berlin", "biz", "br", "ch", "cn",
"co", "cymru", "de", "edu", "eu", "fr", "gov", "hk", "hm", "in", "int", "it", "jp", "kr",
"la", "london", "me", "mo", "museum", "name", "nl", "nz", "pm", "re", "ro", "ru", "sh",
"kz", "su", "tel", "ee", "tf", "tk", "travel", "tw", "uk", "us", "wales", "wf", "xxx",
Expand All @@ -141,7 +141,7 @@ func TestParse(t *testing.T) {
assert.NotZero(t, whoisInfo.Domain.NameServers)
}

if !assert.IsContains([]string{"aq", "au", "de", "eu", "gov", "hm", "name", "nl", "nz", "ir", "tk",
if !assert.IsContains([]string{"aq", "at", "au", "de", "eu", "gov", "hm", "name", "nl", "nz", "ir", "tk",
"xn--mgba3a4f16a"}, extension) &&
!strings.Contains(domain, "ac.jp") &&
!strings.Contains(domain, "co.jp") &&
Expand All @@ -151,13 +151,13 @@ func TestParse(t *testing.T) {
assert.NotNil(t, whoisInfo.Domain.CreatedDateInTime)
}

if !assert.IsContains([]string{"aq", "ch", "cn", "eu", "gov", "hk", "hm", "mo",
if !assert.IsContains([]string{"aq", "at", "ch", "cn", "eu", "gov", "hk", "hm", "mo",
"name", "nl", "ro", "ru", "su", "tk", "tw", "dk", "xn--fiqs8s", "xn--p1ai", "hu"}, extension) {
assert.NotZero(t, whoisInfo.Domain.UpdatedDate)
assert.NotNil(t, whoisInfo.Domain.UpdatedDateInTime)
}

if !assert.IsContains([]string{"", "aq", "au", "br", "ch", "de", "eu", "gov", "ee",
if !assert.IsContains([]string{"", "at", "aq", "au", "br", "ch", "de", "eu", "gov", "ee",
"hm", "int", "name", "nl", "nz", "tk", "kz", "hu"}, extension) &&
!strings.Contains(domain, "ac.jp") &&
!strings.Contains(domain, "co.jp") &&
Expand All @@ -167,19 +167,19 @@ func TestParse(t *testing.T) {
assert.NotNil(t, whoisInfo.Domain.ExpirationDateInTime)
}

if !assert.IsContains([]string{"", "ai", "aq", "au", "br", "ca", "ch", "cn", "cx", "de",
if !assert.IsContains([]string{"", "ai", "at", "aq", "au", "br", "ca", "ch", "cn", "cx", "de",
"edu", "eu", "fr", "gov", "gs", "hk", "hm", "int", "it", "jp", "kr", "kz", "la", "mo", "nl",
"nz", "pl", "pm", "re", "ro", "ru", "su", "tf", "tk", "tw", "uk", "wf", "yt", "ir", "fi", "rs",
"ee", "dk", "by", "ua", "xn--mgba3a4f16a", "xn--fiqs8s", "xn--p1ai", "se", "nu", "hu"}, extension) {
assert.NotZero(t, whoisInfo.Registrar.ID)
}

if !assert.IsContains([]string{"", "aq", "br", "de",
if !assert.IsContains([]string{"", "at", "aq", "br", "de",
"edu", "gov", "hm", "int", "jp", "mo", "tk", "ir", "dk", "xn--mgba3a4f16a", "hu"}, extension) {
assert.NotZero(t, whoisInfo.Registrar.Name)
}

if !assert.IsContains([]string{"", "aero", "ai", "aq", "asia", "au", "br", "ch", "cn", "de",
if !assert.IsContains([]string{"", "aero", "ai", "at", "aq", "asia", "au", "br", "ch", "cn", "de",
"edu", "gov", "hk", "hm", "int", "jp", "kr", "kz", "la", "london", "love", "mo",
"museum", "name", "nl", "nz", "pl", "ru", "su", "tk", "top", "ir", "fi", "rs", "dk", "by", "ua",
"xn--mgba3a4f16a", "xn--fiqs8s", "xn--p1ai", "se", "nu", "hu"}, extension) {
Expand Down
82 changes: 82 additions & 0 deletions prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ func Prepare(text, ext string) (string, bool) { //nolint:cyclop
return prepareBY(text), true
case "ua":
return prepareUA(text), true
case "at":
return prepareAT(text), true
default:
return text, false
}
Expand Down Expand Up @@ -1359,3 +1361,83 @@ func prepareUA(text string) string {

return result
}

// prepareAT prepares the .at domain
func prepareAT(text string) string {
result := ""
registrantID := ""
techID := ""

tokens := map[string]string{
"street address": "address",
"postal code": "address",
"city": "address",
"country": "address",
"e-mail": "email",
"nic-hdl": "id",
"personname": "name",
}

formatLine := func(line, token string) string {
before, after, _ := strings.Cut(line, ":")
key := strings.TrimSpace(before)
if t, ok := tokens[key]; ok {
key = t
}
val := strings.TrimSpace(after)
return fmt.Sprintf("%s %s: %s", token, key, val)
}

for _, v := range strings.Split(text, "\n\n") {
v = strings.TrimSpace(v)
if strings.HasPrefix(v, "%") {
continue
}
if strings.Contains(v, ":") {
b := strings.Split(v, "\n")
if strings.HasPrefix(b[0], "domain") {
for _, l := range b {
w := ""
if before, after, ok := strings.Cut(l, ":"); ok {
key := strings.TrimSpace(before)
val := strings.TrimSpace(after)
switch key {
case "domain":
w = fmt.Sprintf("%s: %s", "domain name", val)
case "registrant":
registrantID = val
case "tech-c":
techID = val
case "changed":
w = fmt.Sprintf("%s: %s", "updated_date", val)
case "nserver":
w = fmt.Sprintf("%s: %s", "name_servers", val)
default:
w = fmt.Sprintf("domain %s: %s", key, val)
}
if w != "" {
result += w + "\n"
}
}
}
} else if strings.HasPrefix(b[0], "personname") {
token := ""
if strings.Contains(v, registrantID) {
token = "registrant"
} else if strings.Contains(v, techID) {
token = "technical contact"
}
if token == "" {
result += v + "\n"
} else {
for _, l := range strings.Split(v, "\n") {
result += formatLine(l, token) + "\n"
}
}
} else {
result += v + "\n"
}
}
}
return result
}
4 changes: 4 additions & 0 deletions testdata/noterror/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ If there is any problem, please feel free to open a new issue.
| .aq | [ats.aq](aq_ats.aq) | [ats.aq](aq_ats.aq.json) ||
| .asia | [git.asia](asia_git.asia) | [git.asia](asia_git.asia.json) ||
| .asia | [google.asia](asia_google.asia) | [google.asia](asia_google.asia.json) ||
| .at | [0wnz.at](at_0wnz.at) | [0wnz.at](at_0wnz.at.json) ||
| .at | [elektro-rauter.at](at_elektro-rauter.at) | [elektro-rauter.at](at_elektro-rauter.at.json) ||
| .at | [rerail.at](at_rerail.at) | [rerail.at](at_rerail.at.json) ||
| .at | [samsung.at](at_samsung.at) | [samsung.at](at_samsung.at.json) ||
| .au | [acma.gov.au](au_acma.gov.au) | [acma.gov.au](au_acma.gov.au.json) ||
| .au | [google.com.au](au_google.com.au) | [google.com.au](au_google.com.au.json) ||
| .berlin | [google.berlin](berlin_google.berlin) | [google.berlin](berlin_google.berlin.json) ||
Expand Down
49 changes: 49 additions & 0 deletions testdata/noterror/at_0wnz.at
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
% Copyright (c)2024 by NIC.AT (1)
%
% Restricted rights.
%
% Except for agreed Internet operational purposes, no part of this
% information may be reproduced, stored in a retrieval system, or
% transmitted, in any form or by any means, electronic, mechanical,
% recording, or otherwise, without prior permission of NIC.AT on behalf
% of itself and/or the copyright holders. Any use of this material to
% target advertising or similar activities is explicitly forbidden and
% can be prosecuted.
%
% It is furthermore strictly forbidden to use the Whois-Database in such
% a way that jeopardizes or could jeopardize the stability of the
% technical systems of NIC.AT under any circumstances. In particular,
% this includes any misuse of the Whois-Database and any use of the
% Whois-Database which disturbs its operation.
%
% Should the user violate these points, NIC.AT reserves the right to
% deactivate the Whois-Database entirely or partly for the user.
% Moreover, the user shall be held liable for any and all damage
% arising from a violation of these points.

domain: 0wnz.at
registrar: NETPLANET GmbH ( https://nic.at/registrar/597 )
registrant: FMR13403268-NICAT
tech-c: FMR13403268-NICAT
nserver: a.ns.0wnz.at
remarks: 89.185.109.153
nserver: b.ns.0wnz.at
remarks: 89.185.109.154
nserver: c.ns.0wnz.at
remarks: 54.38.158.217
nserver: d.ns.0wnz.at
remarks: 78.47.81.186
changed: 20221101 00:10:24
source: AT-DOM

personname: Markus Rambossek
organization: Firma Markus Rambossek
street address: Marianne-Pollak-Gasse 3/5/19
postal code: 1100
city: Wien
country: Austria
phone: <data not disclosed>
e-mail: <data not disclosed>
nic-hdl: FMR13403268-NICAT
changed: 20220619 16:53:33
source: AT-DOM
24 changes: 24 additions & 0 deletions testdata/noterror/at_0wnz.at.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"domain": {
"domain": "0wnz.at",
"punycode": "0wnz.at",
"name": "0wnz",
"extension": "at",
"name_servers": [
"a.ns.0wnz.at",
"b.ns.0wnz.at",
"c.ns.0wnz.at",
"d.ns.0wnz.at"
],
"updated_date": "20221101 00:10:24",
"updated_date_in_time": "2022-11-01T00:10:24Z"
},
"registrant": {
"id": "FMR13403268-NICAT",
"name": "Markus Rambossek",
"organization": "Firma Markus Rambossek",
"street": "Marianne-Pollak-Gasse 3/5/19, 1100, Wien, Austria",
"phone": "<data not disclosed>",
"email": "<data not disclosed>"
}
}
23 changes: 23 additions & 0 deletions testdata/noterror/at_0wnz.at.pre
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
domain name: 0wnz.at
domain registrar: NETPLANET GmbH ( https://nic.at/registrar/597 )
name_servers: a.ns.0wnz.at
domain remarks: 89.185.109.153
name_servers: b.ns.0wnz.at
domain remarks: 89.185.109.154
name_servers: c.ns.0wnz.at
domain remarks: 54.38.158.217
name_servers: d.ns.0wnz.at
domain remarks: 78.47.81.186
updated_date: 20221101 00:10:24
domain source: AT-DOM
registrant name: Markus Rambossek
registrant organization: Firma Markus Rambossek
registrant address: Marianne-Pollak-Gasse 3/5/19
registrant address: 1100
registrant address: Wien
registrant address: Austria
registrant phone: <data not disclosed>
registrant email: <data not disclosed>
registrant id: FMR13403268-NICAT
registrant changed: 20220619 16:53:33
registrant source: AT-DOM
59 changes: 59 additions & 0 deletions testdata/noterror/at_elektro-rauter.at
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
% Copyright (c)2024 by NIC.AT (1)
%
% Restricted rights.
%
% Except for agreed Internet operational purposes, no part of this
% information may be reproduced, stored in a retrieval system, or
% transmitted, in any form or by any means, electronic, mechanical,
% recording, or otherwise, without prior permission of NIC.AT on behalf
% of itself and/or the copyright holders. Any use of this material to
% target advertising or similar activities is explicitly forbidden and
% can be prosecuted.
%
% It is furthermore strictly forbidden to use the Whois-Database in such
% a way that jeopardizes or could jeopardize the stability of the
% technical systems of NIC.AT under any circumstances. In particular,
% this includes any misuse of the Whois-Database and any use of the
% Whois-Database which disturbs its operation.
%
% Should the user violate these points, NIC.AT reserves the right to
% deactivate the Whois-Database entirely or partly for the user.
% Moreover, the user shall be held liable for any and all damage
% arising from a violation of these points.

domain: elektro-rauter.at
registrar: ANEXIA Internetdienstleistungs GmbH ( https://nic.at/registrar/683 )
registrant: ER12589652-NICAT
tech-c: AIG11984868-NICAT
nserver: anexia.fifthns.com
nserver: anexia.firstns.cc
nserver: anexia.fourthns.systems
nserver: anexia.secondns.at
nserver: anexia.thirdns.de
changed: 20230303 06:35:33
source: AT-DOM

personname: Josef Rauter
organization: Elektro Rauter
street address: Sankt Lorenzen 117
postal code: 9654
city: Lesachtal
country: Austria
phone: +4347166240
fax-no: +43471662418
e-mail: domainreg@anexia-it.com
nic-hdl: ER12589652-NICAT
changed: 20200313 10:58:48
source: AT-DOM

personname: Alexander Windbichler
organization: ANEXIA Internetdienstleistungs GmbH
street address: Feldkirchner Strasse 140
postal code: 9020
city: Klagenfurt am Woerthersee
country: Austria
phone: +4350556
e-mail: domainreg@anexia-it.com
nic-hdl: AIG11984868-NICAT
changed: 20190517 16:47:46
source: AT-DOM
34 changes: 34 additions & 0 deletions testdata/noterror/at_elektro-rauter.at.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"domain": {
"domain": "elektro-rauter.at",
"punycode": "elektro-rauter.at",
"name": "elektro-rauter",
"extension": "at",
"name_servers": [
"anexia.fifthns.com",
"anexia.firstns.cc",
"anexia.fourthns.systems",
"anexia.secondns.at",
"anexia.thirdns.de"
],
"updated_date": "20230303 06:35:33",
"updated_date_in_time": "2023-03-03T06:35:33Z"
},
"registrant": {
"id": "ER12589652-NICAT",
"name": "Josef Rauter",
"organization": "Elektro Rauter",
"street": "Sankt Lorenzen 117, 9654, Lesachtal, Austria",
"phone": "+4347166240",
"fax": "+43471662418",
"email": "domainreg@anexia-it.com"
},
"technical": {
"id": "AIG11984868-NICAT",
"name": "Alexander Windbichler",
"organization": "ANEXIA Internetdienstleistungs GmbH",
"street": "Feldkirchner Strasse 140, 9020, Klagenfurt am Woerthersee, Austria",
"phone": "+4350556",
"email": "domainreg@anexia-it.com"
}
}
Loading

0 comments on commit 6b9845e

Please sign in to comment.