diff options
| author | Daniel Langesten <daniel.langest@gmail.com> | 2015-02-25 14:01:04 +0100 |
|---|---|---|
| committer | Daniel Langesten <daniel.langest@gmail.com> | 2015-02-25 14:01:04 +0100 |
| commit | df6005df35ad6b8f6265297d10247f458ede05bc (patch) | |
| tree | a063a1eb625589e72e19d70c41adeaab8fc6094b | |
| parent | 2a9098403281156b2cca1085f5bff3417942dbda (diff) | |
added parsing
| -rw-r--r-- | whois.go | 20 |
1 files changed, 19 insertions, 1 deletions
@@ -4,6 +4,7 @@ import ( "fmt" "io/ioutil" "net" + "strings" "time" ) @@ -14,13 +15,30 @@ const ( RETRIES = 1 ) +type asnipPair struct { + asNum string + ipAdr string +} + func main() { domains := []string{"109.105.104.100", "123.123.123.123"} res, err := whois(domains, WHOIS_SERVER) if err != nil { return } - fmt.Println(res) + + lines := strings.Split(res, "\n") + asip := make([]asnipPair, 0, len(lines)-2) + for _, line := range lines[1 : len(lines)-1] { + content := strings.Split(line, "|") + as := strings.TrimSpace(content[0]) + ip := strings.TrimSpace(content[2]) + asip = append(asip, asnipPair{ + asNum: as, + ipAdr: ip, + }) + } + fmt.Println("cap:", cap(asip), ", len:", len(asip), ", content:", asip) } /* implements the whois protocal described at https://en.wikipedia.org/wiki/Whois#Protocol */ |
