-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue: #1
- Loading branch information
Showing
5 changed files
with
277 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package domain | ||
|
||
import ( | ||
"sort" | ||
"strings" | ||
|
||
"github.com/shlin168/go-whois/whois/utils" | ||
) | ||
|
||
const fiTfmt = "2.1.2006 15:04:05" | ||
|
||
var fiContactKeyMap = map[string]string{ | ||
"holder": "name", | ||
"holder email": "email", | ||
"address": "street", | ||
} | ||
|
||
type FIParser struct{} | ||
|
||
type FITLDParser struct { | ||
parser IParser | ||
stopFunc func(string) bool | ||
} | ||
|
||
func NewFITLDParser() *FITLDParser { | ||
return &FITLDParser{ | ||
parser: NewParser(), | ||
} | ||
} | ||
|
||
func (fiw *FITLDParser) GetName() string { | ||
return "fi" | ||
} | ||
|
||
func (fiw FITLDParser) getKeyValFromLine(line string) (string, string) { | ||
kv := strings.Split(line, "..: ") | ||
if len(kv) == 2 { | ||
return strings.ReplaceAll(kv[0], ".", ""), kv[1] | ||
} | ||
return line, "" | ||
} | ||
|
||
func (fiw *FITLDParser) GetParsedWhois(rawtext string) (*ParsedWhois, error) { | ||
parsedWhois, err := fiw.parser.Do(rawtext, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var contactFlg string | ||
contactsMap := map[string]map[string]interface{}{} | ||
var regContact, techContact map[string]interface{} | ||
lines := strings.Split(strings.ReplaceAll(rawtext, "\r\n", "\n"), "\n") | ||
for _, line := range lines { | ||
key, val := fiw.getKeyValFromLine(line) | ||
if len(key) == 0 { | ||
continue | ||
} | ||
switch key { | ||
case "domain": | ||
parsedWhois.DomainName = val | ||
case "status": | ||
parsedWhois.Statuses = []string{val} | ||
case "created": | ||
parsedWhois.CreatedDateRaw = val | ||
parsedWhois.CreatedDate, _ = utils.ConvTimeFmt(parsedWhois.CreatedDateRaw, fiTfmt, WhoisTimeFmt) | ||
case "expires": | ||
parsedWhois.ExpiredDateRaw = val | ||
parsedWhois.ExpiredDate, _ = utils.ConvTimeFmt(parsedWhois.ExpiredDateRaw, fiTfmt, WhoisTimeFmt) | ||
case "modified": | ||
parsedWhois.UpdatedDateRaw = val | ||
parsedWhois.UpdatedDate, _ = utils.ConvTimeFmt(parsedWhois.UpdatedDateRaw, fiTfmt, WhoisTimeFmt) | ||
case "nserver": | ||
if len(parsedWhois.NameServers) == 0 { | ||
parsedWhois.NameServers = []string{} | ||
} | ||
parsedWhois.NameServers = append(parsedWhois.NameServers, strings.Split(val, " ")[0]) | ||
case "dnssec": | ||
parsedWhois.Dnssec = val | ||
case "Holder": | ||
contactFlg = REGISTRANT | ||
regContact = make(map[string]interface{}) | ||
case "Tech": | ||
contactFlg = TECH | ||
techContact = make(map[string]interface{}) | ||
case "name", "holder", "address", "city", "country", "phone", "holder email", "email", "postal": | ||
var tmpContact map[string]interface{} | ||
switch contactFlg { | ||
case REGISTRANT: | ||
tmpContact = regContact | ||
case TECH: | ||
tmpContact = techContact | ||
} | ||
if tmpContact != nil { | ||
ckey := mapContactKeys(fiContactKeyMap, key) | ||
if ckey == "street" { | ||
if _, ok := tmpContact[ckey]; !ok { | ||
tmpContact[ckey] = []string{} | ||
} | ||
tmpContact[ckey] = append(tmpContact[ckey].([]string), val) | ||
continue | ||
} | ||
tmpContact[ckey] = val | ||
} | ||
case "Registrar": | ||
parsedWhois.Registrar = &Registrar{} | ||
case "registrar": | ||
if parsedWhois.Registrar != nil { | ||
parsedWhois.Registrar.Name = val | ||
} | ||
case "www": | ||
if parsedWhois.Registrar != nil { | ||
parsedWhois.Registrar.URL = val | ||
} | ||
} | ||
} | ||
contactsMap[REGISTRANT] = regContact | ||
contactsMap[TECH] = techContact | ||
contacts, err := map2ParsedContacts(contactsMap) | ||
if err == nil { | ||
parsedWhois.Contacts = contacts | ||
} | ||
sort.Strings(parsedWhois.NameServers) | ||
return parsedWhois, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package domain | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestFIParser(t *testing.T) { | ||
exp := &ParsedWhois{ | ||
DomainName: "zakony.fi", | ||
Registrar: &Registrar{ | ||
Name: "Euronic Oy", | ||
URL: "www.domainkeskus.com", | ||
}, | ||
Statuses: []string{"Registered"}, | ||
NameServers: []string{"ns1.euronic.fi", "ns2.euronic.fi", "ns3.euronic.fi"}, | ||
CreatedDate: "2015-09-16T16:16:22+00:00", | ||
CreatedDateRaw: "16.9.2015 16:16:22", | ||
UpdatedDate: "2020-08-12T13:56:17+00:00", | ||
UpdatedDateRaw: "12.8.2020 13:56:17", | ||
ExpiredDate: "2025-09-16T16:16:21+00:00", | ||
ExpiredDateRaw: "16.9.2025 16:16:21", | ||
Dnssec: "no", | ||
Contacts: &Contacts{ | ||
Registrant: &Contact{ | ||
Name: "Kulttuuri-Innovaatioden Kehitys KIK ry", | ||
Country: "Finland", | ||
City: "Helsinki", | ||
Street: []string{"Sahaajankatu 20 A"}, | ||
Postal: "00880", | ||
}, | ||
}, | ||
} | ||
|
||
checkParserResult(t, "whois.fi", "fi/case1.txt", "fi", exp) | ||
|
||
exp = &ParsedWhois{ | ||
DomainName: "google.fi", | ||
Registrar: &Registrar{ | ||
Name: "MarkMonitor Inc.", | ||
URL: "www.markmonitor.com", | ||
}, | ||
Statuses: []string{"Registered"}, | ||
NameServers: []string{"ns1.google.com", "ns2.google.com", "ns3.google.com", "ns4.google.com"}, | ||
CreatedDate: "2006-06-30T00:00:00+00:00", | ||
CreatedDateRaw: "30.6.2006 00:00:00", | ||
UpdatedDate: "2022-06-02T12:24:38+00:00", | ||
UpdatedDateRaw: "2.6.2022 12:24:38", | ||
ExpiredDate: "2023-07-04T10:15:55+00:00", | ||
ExpiredDateRaw: "4.7.2023 10:15:55", | ||
Dnssec: "no", | ||
Contacts: &Contacts{ | ||
Registrant: &Contact{ | ||
Name: "Google LLC", | ||
Country: "United States of America", | ||
City: "Mountain View", | ||
Street: []string{"1600 Amphitheatre Parkway"}, | ||
Postal: "94043", | ||
}, | ||
Tech: &Contact{ | ||
Name: "Google LLC", | ||
Email: "ccops@markmonitor.com", | ||
}, | ||
}, | ||
} | ||
|
||
checkParserResult(t, "whois.fi", "fi/case2.txt", "fi", exp) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
domain.............: zakony.fi | ||
status.............: Registered | ||
created............: 16.9.2015 16:16:22 | ||
expires............: 16.9.2025 16:16:21 | ||
available..........: 16.10.2025 16:16:21 | ||
modified...........: 12.8.2020 13:56:17 | ||
RegistryLock.......: no | ||
|
||
Nameservers | ||
|
||
nserver............: ns1.euronic.fi [185.55.84.18] [OK] | ||
nserver............: ns2.euronic.fi [185.55.84.19] [OK] | ||
nserver............: ns3.euronic.fi [92.243.25.228] [OK] | ||
|
||
DNSSEC | ||
|
||
dnssec.............: no | ||
|
||
Holder | ||
|
||
name...............: Kulttuuri-Innovaatioden Kehitys KIK ry | ||
register number....: 2616135-5 | ||
address............: Sahaajankatu 20 A | ||
postal.............: 00880 | ||
city...............: Helsinki | ||
country............: Finland | ||
phone..............: | ||
holder email.......: | ||
|
||
Registrar | ||
|
||
registrar..........: Euronic Oy | ||
www................: www.domainkeskus.com | ||
|
||
>>> Last update of WHOIS database: 5.10.2022 19:01:20 (EET) <<< | ||
|
||
|
||
Copyright (c) Finnish Transport and Communications Agency Traficom |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
domain.............: google.fi | ||
status.............: Registered | ||
created............: 30.6.2006 00:00:00 | ||
expires............: 4.7.2023 10:15:55 | ||
available..........: 4.8.2023 10:15:55 | ||
modified...........: 2.6.2022 12:24:38 | ||
holder transfer....: 20.11.2018 00:15:59 | ||
RegistryLock.......: locked | ||
|
||
Nameservers | ||
|
||
nserver............: ns3.google.com [OK] | ||
nserver............: ns4.google.com [OK] | ||
nserver............: ns1.google.com [OK] | ||
nserver............: ns2.google.com [OK] | ||
|
||
DNSSEC | ||
|
||
dnssec.............: no | ||
|
||
Holder | ||
|
||
name...............: Google LLC | ||
register number....: 3582691 | ||
address............: 1600 Amphitheatre Parkway | ||
postal.............: 94043 | ||
city...............: Mountain View | ||
country............: United States of America | ||
phone..............: | ||
holder email.......: | ||
|
||
Registrar | ||
|
||
registrar..........: MarkMonitor Inc. | ||
www................: www.markmonitor.com | ||
|
||
Tech | ||
|
||
name...............: Google LLC | ||
email..............: ccops@markmonitor.com | ||
|
||
>>> Last update of WHOIS database: 5.10.2022 19:00:13 (EET) <<< | ||
|
||
|
||
Copyright (c) Finnish Transport and Communications Agency Traficom |