checking in- working on fix for numhost subnetting
This commit is contained in:
parent
3c239a4d09
commit
fd344f3b8e
@ -39,7 +39,7 @@ A tool to assist in design of segregate/segment/split/subnet networks.
|
|||||||
** For IPv4 addresses, it will be `true` if it is an APIPA (_Automatic Private IP Addressing_) address ({rfc}3927[RFC 3927^]) (in the `169.254.0.0/16` range).
|
** For IPv4 addresses, it will be `true` if it is an APIPA (_Automatic Private IP Addressing_) address ({rfc}3927[RFC 3927^]) (in the `169.254.0.0/16` range).
|
||||||
* `First` and `Last` refer to the first and last "usable" ("host"/assignable) addresses in a subnet/network.
|
* `First` and `Last` refer to the first and last "usable" ("host"/assignable) addresses in a subnet/network.
|
||||||
** Note that for IPv6, the first address (`x::`) in a subnet *may* or *may not* be assignable/"usable". If it is assigned to a device, that device *must* be a router for anycast. See {rfc}4291#section-2.6.1[RFC 4291 § 2.6.1^] for details. In the interest of convenience, `subnetter` will report this address as *not usable/addressable* in ranges for this reason as it is technically not a "host" address.
|
** Note that for IPv6, the first address (`x::`) in a subnet *may* or *may not* be assignable/"usable". If it is assigned to a device, that device *must* be a router for anycast. See {rfc}4291#section-2.6.1[RFC 4291 § 2.6.1^] for details. In the interest of convenience, `subnetter` will report this address as *not usable/addressable* in ranges for this reason as it is technically not a "host" address.
|
||||||
** Note that for IPv6, some subnetting calculators erroneously report the last address for /64's (e.g. `x:ffff:ffff:ffff:ffff/64`) as usable. They are actually reserved in strictly RFC-compliant networks for EUI-64 reasons (per {rfc}2526[RFC 2526^]). For this reason, *if and only if* a prefix is a /64 *exactly*, `subnetter` will use `x:ffff:ffff:ffff:fffe` as the last host address.
|
** Note that for IPv6, some subnetting calculators erroneously report the last address as usable. They are reserved in strictly RFC-compliant networks for anycast reasons (per {rfc}2526[RFC 2526^]). Subnetter follows RFC as closely as possible, and any deviation from RFC is considered a bug -- as such, the last address of IPv6 subnets is considered *not usable/addressable*.
|
||||||
** There are additional restrictions for /64 subnets, but they fall earlier in the range. These are *not explicitly excluded* in the usable host range, nor are they excluded from the total host count.
|
** There are additional restrictions for /64 subnets, but they fall earlier in the range. These are *not explicitly excluded* in the usable host range, nor are they excluded from the total host count.
|
||||||
* Private networks ({rfc}1918[RFC 1918^]), ULA prefixes ({rfc}4193[RFC 4193^]), and documentation prefixes ({rfc}3849[RFC 3849^], {rfc}5737[RFC 5737^], {rfc}9637[RFC 9637^]) are treated as "normal" networks (in that it is allowed to subnet them).
|
* Private networks ({rfc}1918[RFC 1918^]), ULA prefixes ({rfc}4193[RFC 4193^]), and documentation prefixes ({rfc}3849[RFC 3849^], {rfc}5737[RFC 5737^], {rfc}9637[RFC 9637^]) are treated as "normal" networks (in that it is allowed to subnet them).
|
||||||
* Various other reserved IPv4 and IPv6 addresses/networks will print warnings with their corresponding RFC(s) (unless `-R`/`--allow-reserved` is specified) if they are specified as/included in the initial prefix/network. ({rfc}6890[RFC 6890^] and its update via {rfc}8190[RFC 8190^] are useful summaries.) Note that for checking to function, an Internet connection is required as it pulls it directly from IANA live to ensure the data is accurate to standards. This may be cached locally if `-c`/`--cache-reservations` is specified, in which case a locally-cached copy will be used if present and populated then used if not.
|
* Various other reserved IPv4 and IPv6 addresses/networks will print warnings with their corresponding RFC(s) (unless `-R`/`--allow-reserved` is specified) if they are specified as/included in the initial prefix/network. ({rfc}6890[RFC 6890^] and its update via {rfc}8190[RFC 8190^] are useful summaries.) Note that for checking to function, an Internet connection is required as it pulls it directly from IANA live to ensure the data is accurate to standards. This may be cached locally if `-c`/`--cache-reservations` is specified, in which case a locally-cached copy will be used if present and populated then used if not.
|
||||||
|
@ -4,7 +4,8 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"fmt"
|
"fmt"
|
||||||
`math`
|
"math"
|
||||||
|
"math/big"
|
||||||
"net"
|
"net"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"strings"
|
"strings"
|
||||||
@ -376,6 +377,28 @@ func MaskInvert(mask net.IPMask) (inverted net.IPMask) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
NumAddrsNet returns the number of IP addresses in a net.IPNet.
|
||||||
|
|
||||||
|
# The network address is included in the count if inclNet is true, otherwise it is excluded
|
||||||
|
|
||||||
|
Only assignable addresses ("hosts") are considered if hostsOnly is true,
|
||||||
|
otherwise all addresses are counted (depending on inclNet).
|
||||||
|
*/
|
||||||
|
func NumAddrsNet(pfx *net.IPNet, inclNet, hostsOnly bool) (numAddrs *big.Int) {
|
||||||
|
|
||||||
|
if pfx == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// NumAddrsPfx is the exact same as NumAddrsNet but for a net/netip.Prefix instead.
|
||||||
|
// TODO
|
||||||
|
|
||||||
/*
|
/*
|
||||||
NumNets returns the number of times prefix size subnet fits into prefix size network.
|
NumNets returns the number of times prefix size subnet fits into prefix size network.
|
||||||
|
|
||||||
@ -397,9 +420,7 @@ func NumNets(subnet, network uint8) (numNets uint, ipv6Only bool, err error) {
|
|||||||
err = ErrBigPrefix
|
err = ErrBigPrefix
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if network > maxBitsv4 {
|
ipv6Only = (network > maxBitsv4) || (subnet > maxBitsv4)
|
||||||
ipv6Only = true
|
|
||||||
}
|
|
||||||
|
|
||||||
x = float64(subnet - network)
|
x = float64(subnet - network)
|
||||||
|
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
package netsplit
|
package netsplit
|
||||||
|
|
||||||
import (
|
import (
|
||||||
`math/big`
|
"fmt"
|
||||||
`net`
|
"math/big"
|
||||||
|
"net"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
|
|
||||||
`github.com/projectdiscovery/mapcidr`
|
"github.com/projectdiscovery/mapcidr"
|
||||||
"go4.org/netipx"
|
"go4.org/netipx"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -34,6 +35,8 @@ func (h *HostSplitter) Split() (nets []*netip.Prefix, remaining *netipx.IPSet, e
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println(split)
|
||||||
|
|
||||||
tgt = big.NewInt(0)
|
tgt = big.NewInt(0)
|
||||||
tgt.SetUint64(uint64(h.NumberHosts))
|
tgt.SetUint64(uint64(h.NumberHosts))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user