this is cool and all but the tables don't render properly
This commit is contained in:
@@ -6,24 +6,26 @@ import (
|
||||
"encoding/json"
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"github.com/goccy/go-yaml"
|
||||
"github.com/projectdiscovery/mapcidr"
|
||||
"go4.org/netipx"
|
||||
"io"
|
||||
"net"
|
||||
"net/netip"
|
||||
"os"
|
||||
"strings"
|
||||
"subnetter/netsplit"
|
||||
"time"
|
||||
|
||||
"github.com/goccy/go-yaml"
|
||||
"github.com/projectdiscovery/mapcidr"
|
||||
"go4.org/netipx"
|
||||
"subnetter/netsplit"
|
||||
`subnetter/version`
|
||||
)
|
||||
|
||||
func printHostPrefix(label string, pfx *netip.Prefix, verb, indent int, indentStr string) (out string) {
|
||||
|
||||
var maskEvery uint
|
||||
var sb *strings.Builder = new(strings.Builder)
|
||||
var pre string = strings.Repeat(indentStr, indent)
|
||||
var pre2 string = strings.Repeat(indentStr, indent+1)
|
||||
var sb = new(strings.Builder)
|
||||
var pre = strings.Repeat(indentStr, indent)
|
||||
var pre2 = strings.Repeat(indentStr, indent+1)
|
||||
|
||||
if pfx == nil {
|
||||
fmt.Fprintf(sb, "%s%s:\n%sAddress:\t(N/A)\n", pre, label, pre2)
|
||||
@@ -102,10 +104,10 @@ func printMask(label string, pfx netip.Prefix, verb, indent int, indentStr strin
|
||||
var mask net.IPMask
|
||||
var first netip.Addr
|
||||
var last netip.Addr
|
||||
var sb *strings.Builder = new(strings.Builder)
|
||||
var pre string = strings.Repeat(indentStr, indent)
|
||||
var pre2 string = strings.Repeat(indentStr, indent+1)
|
||||
var pre3 string = strings.Repeat(indentStr, indent+2)
|
||||
var sb = new(strings.Builder)
|
||||
var pre = strings.Repeat(indentStr, indent)
|
||||
var pre2 = strings.Repeat(indentStr, indent+1)
|
||||
var pre3 = strings.Repeat(indentStr, indent+2)
|
||||
|
||||
if !pfx.IsValid() {
|
||||
return
|
||||
@@ -156,7 +158,8 @@ func printMask(label string, pfx netip.Prefix, verb, indent int, indentStr strin
|
||||
fmt.Fprintf(sb, "%sBits:\t\t%d\n", pre2, pfx.Bits())
|
||||
fmt.Fprintf(sb, "%sFirst:\t\t%s\n", pre2, first.String())
|
||||
fmt.Fprintf(sb, "%sLast:\t\t%s\n", pre2, last.String())
|
||||
fmt.Fprintf(sb, "%sAddresses:\t%d\n", pre2, mapcidr.CountIPsInCIDR())
|
||||
fmt.Fprintf(sb, "%sAddresses:\t%d\n", pre2, mapcidr.CountIPsInCIDR(true, true, netipx.PrefixIPNet(pfx.Masked())))
|
||||
fmt.Fprintf(sb, "%sHosts:\t\t%d\n", pre2, mapcidr.CountIPsInCIDR(false, false, netipx.PrefixIPNet(pfx.Masked())))
|
||||
if verb >= 2 {
|
||||
fmt.Fprintf(sb, "%sExpanded:\t%s\n", pre2, netsplit.MaskExpand(mask, pfx.Addr().Is6()))
|
||||
fmt.Fprintf(sb, "%sHex:\t\t0x%s\n", pre2, mask.String())
|
||||
@@ -215,7 +218,7 @@ func printNets(orig *netip.Prefix, origNet *net.IPNet, nets []*netip.Prefix, rem
|
||||
var remPfxs []*netip.Prefix
|
||||
var invertedMask net.IPMask
|
||||
var res *netsplit.StructuredResults
|
||||
var verb int = -1
|
||||
var verb = -1
|
||||
|
||||
if orig == nil {
|
||||
return
|
||||
@@ -341,7 +344,6 @@ func printNets(orig *netip.Prefix, origNet *net.IPNet, nets []*netip.Prefix, rem
|
||||
}
|
||||
} else {
|
||||
buf = new(bytes.Buffer)
|
||||
// TODO: data-formatted/structured output
|
||||
if res, err = netsplit.Contain(orig, nets, remaining, splitter); err != nil {
|
||||
return
|
||||
}
|
||||
@@ -355,11 +357,11 @@ func printNets(orig *netip.Prefix, origNet *net.IPNet, nets []*netip.Prefix, rem
|
||||
fmt.Fprintf(
|
||||
buf,
|
||||
`<?xml version="1.0" encoding="UTF-8"?>`+
|
||||
"<!--\n"+
|
||||
" Generated by subnetter.\n"+
|
||||
"\n<!--\n"+
|
||||
" Generated by subnetter %s\n"+
|
||||
" %s\n"+
|
||||
"-->\n",
|
||||
time.Now().String(),
|
||||
version.Ver.Short(), time.Now().String(),
|
||||
)
|
||||
if b, err = xml.MarshalIndent(res, "", " "); err != nil {
|
||||
return
|
||||
@@ -368,9 +370,9 @@ func printNets(orig *netip.Prefix, origNet *net.IPNet, nets []*netip.Prefix, rem
|
||||
case "yml":
|
||||
fmt.Fprintf(
|
||||
buf,
|
||||
"# Generated by subnetter.\n"+
|
||||
"# Generated by subnetter %s\n"+
|
||||
"# %s\n\n",
|
||||
time.Now().String(),
|
||||
version.Ver.Short(), time.Now().String(),
|
||||
)
|
||||
if b, err = yaml.Marshal(res); err != nil {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user