Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieve Name servers displayed on multiple lines #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions extra.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package whois

import (
"bufio"
"regexp"
"strings"
)
Expand All @@ -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])

}
}
}
Expand All @@ -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)^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)+)`)
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
Expand Down