Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
95a473a22d |
15
main.go
15
main.go
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user