Compare commits

...

1 Commits

Author SHA1 Message Date
Stephen McQuay 95a473a22d
find space-delimited ip address anywhere in line
I'd prefer this were more robust and perhaps used a regexp.
2018-04-03 09:42:10 -07:00
1 changed files with 14 additions and 1 deletions

15
main.go
View File

@ -9,6 +9,7 @@ import (
"net"
"os"
"sort"
"strings"
)
type lines []string
@ -16,7 +17,19 @@ type lines []string
func (l lines) Len() int { return len(l) }
func (l lines) Swap(i, j int) { l[i], l[j] = l[j], l[i] }
func (l lines) Less(i, j int) bool {
a, b := net.ParseIP(l[i]), net.ParseIP(l[j])
var a, b net.IP
for _, s := range strings.Fields(l[i]) {
a = net.ParseIP(s)
if a != nil {
break
}
}
for _, s := range strings.Fields(l[j]) {
b = net.ParseIP(s)
if b != nil {
break
}
}
return bytes.Compare(a, b) < 0
}