Skip to content

Commit

Permalink
nicer output for ip checker
Browse files Browse the repository at this point in the history
  • Loading branch information
Jozef Reisinger committed Oct 15, 2021
1 parent fbf2a17 commit 7d4b607
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package checkip
import (
"fmt"
"net"
"strconv"
"strings"
)

// IP holds info from net.IP.
Expand All @@ -20,5 +22,13 @@ func (i *IP) Check(ipaddr net.IP) (bool, error) {

// String returns the result of the check.
func (i *IP) String() string {
return fmt.Sprintf("RFC 1918 private: %v, default mask: %d", i.Private, i.DefaultMask)
private := "RFC 1918 private"
if !i.Private {
private = "not " + private
}
var mask []string
for _, b := range i.DefaultMask {
mask = append(mask, strconv.Itoa(int(b)))
}
return fmt.Sprintf("%s, default mask %s", private, strings.Join(mask, "."))
}

0 comments on commit 7d4b607

Please sign in to comment.