ADDED:
* netx.IsPub
* encodingx/hexx

Rest are mostly small corrections and docs
This commit is contained in:
brent saner
2026-06-22 18:51:13 -04:00
parent c6fc692f5e
commit 58556d7281
35 changed files with 5492 additions and 2486 deletions
+147
View File
@@ -0,0 +1,147 @@
package main
import (
"log"
"maps"
"net/netip"
`os`
"slices"
"github.com/olekukonko/tablewriter"
`github.com/olekukonko/tablewriter/tw`
)
type (
IpInfo struct {
Desc string `r:"-"`
IP netip.Addr `r:"-"`
Is4 bool
Is4In6 bool
Is6 bool
IsGlobalUnicast bool
IsInterfaceLocalMulticast bool
IsLinkLocalMulticast bool
IsLinkLocalUnicast bool
IsLoopback bool
IsMulticast bool
IsPrivate bool
IsUnspecified bool
IsValid bool
}
)
func main() {
var err error
var s string
var idx int
var desc string
var ip netip.Addr
var rows []IpInfo
/*
var typ reflect.Type
var val reflect.Value
var fieldVal reflect.Value
var field reflect.StructField
*/
var exampleAddrs map[string]string
var tbl *tablewriter.Table = tablewriter.NewTable(
os.Stdout,
tablewriter.WithBehavior(
tw.Behavior{
Structs: tw.Struct{
AutoHeader: tw.On,
},
},
),
tablewriter.WithRendition(
tw.Rendition{
Settings: tw.Settings{
Separators: tw.Separators{BetweenRows: tw.On},
},
},
),
)
defer func() {
var tErr error
if tbl != nil {
if tErr = tbl.Close(); tErr != nil {
log.Printf("Error closing table: %v", tErr)
}
}
}()
exampleAddrs = map[string]string{
"IPv4": "203.0.113.10", // RFC 5737 address (https://datatracker.ietf.org/doc/html/rfc5737)
"IPv4 Unspecified": "0.0.0.0",
"IPv4 Global Unicast": "173.230.132.76", // r00t2.io
"IPv4 Multicast (All) (RFC 1112 § 4)": "224.0.0.1", // Should encompass all the multicast below. 224.0.0.0 is reserved.
"IPv4 Multicast (Reserved) (RFC 1112 § 4)": "224.0.0.0", // Reserved per RFC but it should still report multicast.
"IPv4 Multicast (Link-Local Multicast/Local Network Control Block) (RFC 5771 § 4)": "224.0.0.18", // https://datatracker.ietf.org/doc/html/rfc5771#section-4 (VRRP multicast addr)
"IPv4 Multicast (Internetwork Control Block) (RFC 5771 § 5)": "224.0.1.68", // https://datatracker.ietf.org/doc/html/rfc5771#section-5 (mdhcpdiscover, RFC 2730)
"IPv4 Multicast (AD-HOC I) (RFC 5771 § 6)": "224.0.2.10", // https://datatracker.ietf.org/doc/html/rfc5771#section-6
"IPv4 Multicast (SDP/SAP) (RFC 5771 § 7)": "224.2.0.10", // https://datatracker.ietf.org/doc/html/rfc5771#section-7
"IPv4 Multicast (AD-HOC II) (RFC 5771 § 6)": "224.3.0.10", // (above)
"IPv4 Multicast (Source-Specific) (RFC 5771 § 8)": "232.0.0.10", // https://datatracker.ietf.org/doc/html/rfc5771#section-8
"IPv4 Multicast (GLOP) (RFC 5771 § 9)": "233.0.0.10", // https://datatracker.ietf.org/doc/html/rfc5771#section-9
"IPv4 Multicast (AD-HOC III) (RFC 5771 § 6)": "233.252.0.10", // (above)
"IPv4 Multicast (Administrative) (RFC 5771 § 10)": "239.0.0.10", // https://datatracker.ietf.org/doc/html/rfc5771#section-10
"IPv4 Link-Local Unicast (RFC 3927 § 2.1)": "169.254.1.10", // https://datatracker.ietf.org/doc/html/rfc3927#section-2.1
"IPv4 Loopback": "127.0.1.10", // It's actually 127/8. Cannot believe how many people do not know this.
"IPv4 Private (RFC 1918)": "10.0.0.10", // https://datatracker.ietf.org/doc/html/rfc1918
"4-in-6 (RFC 4291 § 2.5.5.1)": "::203.0.113.10", // https://datatracker.ietf.org/doc/html/rfc4291#section-2.5.5.1
"4-in-6 (RFC 4291 § 2.5.5.1) (Native)": "::cb00:710a", // ""
"4-in-6 (RFC 4291 § 2.5.5.2)": "::ffff:203.0.113.10", // https://datatracker.ietf.org/doc/html/rfc4291#section-2.5.5.2
"4-in-6 (RFC 4291 § 2.5.5.2) (Native)": "::ffff:cb00:710a", // ""
"IPv6": "2001:db8::cb00:710a", // RFC 3849 (https://datatracker.ietf.org/doc/html/rfc3849) / RFC 9637 (https://datatracker.ietf.org/doc/html/rfc9637) address
"IPv6 Unspecified": "::",
"IPv6 Global Unicast": "2600:3c02::f03c:91ff:fe93:c0a7", // r00t2.io
"IPv6 Multicast (RFC 4291 § 2.7.1) (Reserved Net)": "ff00::", // https://datatracker.ietf.org/doc/html/rfc4291#section-2.7.1
"IPv6 Multicast (RFC 4291 § 2.7.1) (Reserved)": "ff00::1", // ""
"IPv6 Multicast (RFC 4291 § 2.7.1) (All Nodes) (Interface-Local)": "ff01::1", // ""
"IPv6 Multicast (RFC 4291 § 2.7.1) (All Nodes) (Link-Local)": "ff02::1", // ""
"IPv6 Multicast (RFC 4291 § 2.7.1) (All Routers) (Interface-Local)": "ff01::2", // ""
"IPv6 Multicast (RFC 4291 § 2.7.1) (All Routers) (Link-Local)": "ff02::2", // ""
"IPv6 Multicast (RFC 4291 § 2.7.1) (All Routers) (Admin-Local)": "ff04::2", // ""
"IPv6 Multicast (RFC 4291 § 2.7.1) (All Routers) (Site-Local)": "ff05::2", // ""
"IPv6 Multicast (RFC 4291 § 2.7.1) (All Routers) (Org-Local)": "ff08::2", // ""
"IPv6 Multicast (RFC 4291 § 2.7.1) (All Routers) (Internet/Global)": "ff0e::2", // ""
"IPv6 Multicast (RFC 4291 § 2.7.1) (Solicited Node)": "ff02::1:ff00:10", // ""
"IPv6 Link-Local Unicast (RFC 4291 § 2.5.6)": "fe80::cb00:710a", // https://datatracker.ietf.org/doc/html/rfc4291#section-2.5.6
"IPv6 Loopback": "::1", // It's explicitly always a /128 with the address ::1 per RFC 4291 § 2.5.3.
"IPv6 Private (Unique-Local Addresses) (RFC 4193) (Reserved)": "fc00::10", // https://datatracker.ietf.org/doc/html/rfc4193
"IPv6 Private (Unique-Local Addresses) (RFC 4193) (Valid)": "fd00::10", // ""
}
rows = make([]IpInfo, len(exampleAddrs))
for idx, desc = range slices.Sorted(maps.Keys(exampleAddrs)) {
s = exampleAddrs[desc]
if ip, err = netip.ParseAddr(s); err != nil {
log.Panicln(err)
}
// Currently no way to skip cols etc. https://github.com/olekukonko/tablewriter/issues/317
rows[idx] = IpInfo{
Desc: desc,
IP: ip,
Is4: ip.Is4(),
Is4In6: ip.Is4In6(),
Is6: ip.Is6(),
IsGlobalUnicast: ip.IsGlobalUnicast(),
IsInterfaceLocalMulticast: ip.IsInterfaceLocalMulticast(),
IsLinkLocalMulticast: ip.IsLinkLocalMulticast(),
IsLinkLocalUnicast: ip.IsLinkLocalUnicast(),
IsLoopback: ip.IsLoopback(),
IsMulticast: ip.IsMulticast(),
IsPrivate: ip.IsPrivate(),
IsUnspecified: ip.IsUnspecified(),
IsValid: ip.IsValid(),
}
}
if err = tbl.Bulk(rows); err != nil {
log.Panicln(err)
}
if err = tbl.Render(); err != nil {
log.Panicln(err)
}
}