From bb74bcadd4e1186face46d798ea0ae1d0559f024 Mon Sep 17 00:00:00 2001 From: HopHouse Date: Fri, 20 Nov 2020 14:49:58 +0100 Subject: [PATCH 1/2] Retrieve Name servers displayed on multiple lines Name Servers are displayed with one item per line or on multiple lines. Change the function to parse both ways. --- extra.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/extra.go b/extra.go index 299cc95..7ce3e7f 100644 --- a/extra.go +++ b/extra.go @@ -13,6 +13,7 @@ package whois import ( + "bufio" "regexp" "strings" ) @@ -24,9 +25,7 @@ func parser(re *regexp.Regexp, group int, data string) (result []string) { if len(found) > 0 { for _, one := range found { if len(one) >= 2 && len(one[group]) > 0 { - result = appendIfMissing(result, one[group]) - } } } @@ -36,9 +35,25 @@ func parser(re *regexp.Regexp, group int, data string) (result []string) { //Parse uniq name servers from whois func ParseNameServers(whois string) []string { + + resultNameServers := parser(regexp.MustCompile(`(?i)Name Server:\s+(.*?)(\s|$)`), 1, whois) + + if len(resultNameServers) == 0 { + var re = regexp.MustCompile(`(?i)(Name servers:\n(?:\s+(?:[a-zA-Z-_\.0-9]+)\n)+)`) + nameServersString := re.FindString(whois) - return parser(regexp.MustCompile(`(?i)Name Server:\s+(.*?)(\s|$)`), 1, whois) + scanner := bufio.NewScanner(strings.NewReader(nameServersString)) + // Read first line, ie. Name Servers: + scanner.Scan() + // Iterate over Name Servers + for scanner.Scan() { + resultNameServers = append(resultNameServers, strings.TrimSpace(scanner.Text())) + } + + } + + return resultNameServers } //Parse uniq domain status(codes) from whois From ef4b2ee3bb08a367e4cd03877e87bb131b4a4e3b Mon Sep 17 00:00:00 2001 From: HopHouse Date: Tue, 1 Dec 2020 14:46:57 +0100 Subject: [PATCH 2/2] Change regex for "Name Server"line to also match "nserver" name in whois results. --- extra.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extra.go b/extra.go index 7ce3e7f..eadf467 100644 --- a/extra.go +++ b/extra.go @@ -36,7 +36,7 @@ func parser(re *regexp.Regexp, group int, data string) (result []string) { //Parse uniq name servers from whois func ParseNameServers(whois string) []string { - resultNameServers := parser(regexp.MustCompile(`(?i)Name Server:\s+(.*?)(\s|$)`), 1, whois) + resultNameServers := parser(regexp.MustCompile(`(?i)^N(?:.*)Server:\s+(.*?)(?:\s|$)`), 1, whois) if len(resultNameServers) == 0 { var re = regexp.MustCompile(`(?i)(Name servers:\n(?:\s+(?:[a-zA-Z-_\.0-9]+)\n)+)`)