Documentation ¶
Index ¶
- Constants
- Variables
- func CIDRsFromIP6RangeStrRaw(rStr string) ([]string, error)
- func CIDRsFromIPRangeStrRaw(rStr string) ([]string, error)
- func DecimalStrToIP(decimal string, forceIPv6 bool) (net.IP, error)
- func FileExists(pathToFile string) bool
- func GetInputFrom(inputs []string, stdin bool, file bool, ...) error
- func IP4toInt(IPv4Address net.IP) int64
- func IP6toInt(IPv6Address net.IP) *big.Int
- func IPListFromAllSrcs(inputs []string) ([]net.IP, error)
- func IPListFromCIDR(cidrStr string) ([]net.IP, error)
- func IPListFromCIDRs(cidrStrs []string) (ips []net.IP, err error)
- func IPListFromFile(pathToFile string) ([]net.IP, error)
- func IPListFromFiles(paths []string) (ips []net.IP, err error)
- func IPListFromRange(ipStrStart string, ipStrEnd string) ([]net.IP, error)
- func IPListFromRangeStr(rStr string) ([]net.IP, error)
- func IPListFromReader(r io.Reader, breakOnEmptyLine bool) []net.IP
- func IPListFromStdin() []net.IP
- func IPListWriteAllFromFile(pathToFile string) error
- func IPListWriteAllFromFiles(paths []string) error
- func IPListWriteAllFromReader(r io.Reader, breakOnEmptyLine bool)
- func IPListWriteAllFromStdin()
- func IPListWriteFrom(inputs []string, stdin bool, ip bool, iprange bool, cidr bool, file bool) error
- func IPListWriteFromAllSrcs(inputs []string) error
- func IPListWriteFromCIDR(cidrStr string) error
- func IPListWriteFromCIDRs(cidrStrs []string) error
- func IPListWriteFromFile(pathToFile string, ip bool, iprange bool, cidr bool) error
- func IPListWriteFromFiles(paths []string, ip bool, iprange bool, cidr bool) error
- func IPListWriteFromIPRange(ipStrStart string, ipStrEnd string) error
- func IPListWriteFromIPRangeStr(rStr string) error
- func IPListWriteFromReader(r io.Reader, ip bool, iprange bool, cidr bool, breakOnEmptyLine bool)
- func IPListWriteFromStdin(ip bool, iprange bool, cidr bool)
- func IPtoDecimalStr(strIP string) (string, error)
- func InputHelper(str string, op func(string, INPUT_TYPE) error) error
- func IpAdd(input string, delta int) net.IP
- func IsBogonIP4(ip uint32) bool
- func IsBogonIP6(ip6 U128) bool
- func NetAndHostMasks(size uint32) (uint32, uint32)
- func NetAndHostMasks6(size uint32) (U128, U128)
- func ProcessStringsFromFile(filename string, op func(input string, inputType INPUT_TYPE) error) error
- func ProcessStringsFromStdin(op func(input string, inputType INPUT_TYPE) error) error
- func RandIP4(noBogon bool) net.IP
- func RandIP4List(n int, noBogon bool) []net.IP
- func RandIP4ListWrite(n int, noBogon bool)
- func RandIP4Range(iprange IP4Range, noBogon bool) (net.IP, error)
- func RandIP4RangeListWrite(startIP string, endIP string, n int, noBogon bool, unique bool) error
- func RandIP6(noBogon bool) net.IP
- func RandIP6List(n int, noBogon bool) []net.IP
- func RandIP6ListWrite(n int, noBogon bool)
- func RandIP6Range(ipRange IP6RangeInt, noBogon bool) net.IP
- func RandIP6RangeListWrite(startIP string, endIP string, n int, noBogon bool, unique bool) error
- func StrIsASNStr(asn string) bool
- func StrIsCIDR6Str(cidrStr string) bool
- func StrIsCIDRStr(cidrStr string) bool
- func StrIsIP6RangeStr(r string) bool
- func StrIsIP6Str(ipStr string) bool
- func StrIsIPRangeStr(r string) bool
- func StrIsIPStr(ipStr string) bool
- func StrIsIPv4Str(expression string) bool
- func StrIsIPv6Str(expression string) bool
- func StringSliceRev(s []string)
- type CIDR
- type INPUT_TYPE
- type IP
- type IP4Range
- type IP6
- func (ip1 IP6) Cmp(ip2 IP6) int
- func (ip1 IP6) Eq(ip2 IP6) bool
- func (ip1 IP6) Gt(ip2 IP6) bool
- func (ip1 IP6) Gte(ip2 IP6) bool
- func (ip1 IP6) Lt(ip2 IP6) bool
- func (ip1 IP6) Lte(ip2 IP6) bool
- func (ip IP6) String() string
- func (ip IP6) To16ByteSlice() []byte
- func (ip IP6) To16Bytes() [16]byte
- func (ip IP6) ToStdIP() net.IP
- type IP6CIDR
- type IP6Range
- type IP6RangeInt
- type IP6RangeStr
- type IP6Subnet
- type IPCIDR
- type IPRange
- type IPRangeStr
- type IPStr
- type IPSubnet
- type U128
- func (v1 U128) Add(v2 U128) (U128, uint64)
- func (v1 U128) Add64(v2 uint64) (U128, uint64)
- func (v U128) AddOne() U128
- func (v1 U128) And(v2 U128) U128
- func (v1 U128) And64(v2 uint64) U128
- func (v U128) ClearBitsFrom(i uint8) U128
- func (v U128) ClearBitsUpto(i uint8) U128
- func (v1 U128) Cmp(v2 U128) int
- func (v1 U128) Eq(v2 U128) bool
- func (v1 U128) Gt(v2 U128) bool
- func (v1 U128) Gte(v2 U128) bool
- func (v U128) IsMax() bool
- func (v U128) IsZero() bool
- func (v U128) LeadingZeros() int
- func (v U128) Len() int
- func (v1 U128) Lt(v2 U128) bool
- func (v1 U128) Lte(v2 U128) bool
- func (v U128) Not() U128
- func (v U128) OnesCount() int
- func (v1 U128) Or(v2 U128) U128
- func (v1 U128) Or64(v2 uint64) U128
- func (v U128) Reverse() U128
- func (v U128) ReverseBytes() U128
- func (v U128) SetBitsFrom(i uint8) U128
- func (v U128) SetBitsUpto(i uint8) U128
- func (v1 U128) Sub(v2 U128) (U128, uint64)
- func (v1 U128) Sub64(v2 uint64) (U128, uint64)
- func (v U128) SubOne() U128
- func (v U128) TrailingZeros() int
- func (v1 U128) Xor(v2 U128) U128
- func (v1 U128) Xor64(v2 uint64) U128
Constants ¶
const IPv4CIDRRegexPattern = IPv4RegexPattern + `\/([1-2]?[0-9]|3[0-2])`
const IPv4RangeRegexPattern = IPv4RegexPattern + `[-,]` + IPv4RegexPattern
const IPv4RegexPattern = `(` + V4Octet + `\.){3}` + V4Octet
const IPv6CIDRRegexPattern = IPv6RegexPattern + `\/([0-9]|[1-9][0-9]|1[0-1][0-9]|12[0-8])`
const IPv6RangeRegexPattern = IPv6RegexPattern + `[-,]` + IPv6RegexPattern
const IPv6RegexPattern = `` /* 659-byte string literal not displayed */
const V4Octet = `(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)`
Variables ¶
var ( // ErrNotASN is returned when the input is not in proper ASN form. ErrNotASN = errors.New("not asn") // ErrNotIP is returned when the input is not in proper IP form. ErrNotIP = errors.New("not ip") // ErrNotCIDR is returned when the input is not in proper CIDR form. ErrNotCIDR = errors.New("not cidr") // ErrNotIPRange is returned when the input is not in proper IP range form. ErrNotIPRange = errors.New("not ip range") // ErrNotIP6Range is returned when the input is not in proper IPv6 range // form. ErrNotIP6Range = errors.New("not ipv6 range") // ErrNotFile is returned when the input is not an actual file. ErrNotFile = errors.New("not file") // ErrMissingCIDRsOrIPRange is returned when a CIDR or IP range is missing. ErrMissingCIDRsOrIPRange = errors.New("missing CIDRs or IP range") // ErrCannotMixCIDRAndIPs is returned when CIDRs and IPs are mixed. ErrCannotMixCIDRAndIPs = errors.New("cannot mix CIDRs and IPs") // ErrIPRangeRequiresTwoIPs is returned when the IP range is incomplete. ErrIPRangeRequiresTwoIPs = errors.New("IP range requires 2 IPs") // ErrInvalidInput is returned as a generic error for bad input. ErrInvalidInput = errors.New("invalid input") )
var BogonIP4List []IPRange
these lists are initialized on startup inside this pkg's `init`.
var BogonIP6List []IP6Range
var BogonRange4Str []string = []string{
"0.0.0.0/8",
"10.0.0.0/8",
"100.64.0.0/10",
"127.0.0.0/8",
"169.254.0.0/16",
"172.16.0.0/12",
"192.0.0.0/24",
"192.0.2.0/24",
"192.168.0.0/16",
"198.18.0.0/15",
"198.51.100.0/24",
"203.0.113.0/24",
"224.0.0.0/4",
"240.0.0.0/4",
"255.255.255.255/32",
}
list of bogon IPv4 IPs.
var BogonRange6Str []string = []string{
"::/128",
"::1/128",
"::ffff:0:0/96",
"::/96",
"100::/64",
"2001:10::/28",
"2001:db8::/32",
"fc00::/7",
"fe80::/10",
"fec0::/10",
"ff00::/8",
"2002::/24",
"2002:a00::/24",
"2002:7f00::/24",
"2002:a9fe::/32",
"2002:ac10::/28",
"2002:c000::/40",
"2002:c000:200::/40",
"2002:c0a8::/32",
"2002:c612::/31",
"2002:c633:6400::/40",
"2002:cb00:7100::/40",
"2002:e000::/20",
"2002:f000::/20",
"2002:ffff:ffff::/48",
"2001::/40",
"2001:0:a00::/40",
"2001:0:7f00::/40",
"2001:0:a9fe::/48",
"2001:0:ac10::/44",
"2001:0:c000::/56",
"2001:0:c000:200::/56",
"2001:0:c0a8::/48",
"2001:0:c612::/47",
"2001:0:c633:6400::/56",
"2001:0:cb00:7100::/56",
"2001:0:e000::/36",
"2001:0:f000::/36",
"2001:0:ffff:ffff::/64",
}
list of bogon IPv6 IPs.
var CidrRegex *regexp.Regexp
var IpCidrRegex *regexp.Regexp
var IpRangeRegex *regexp.Regexp
var IpRegex *regexp.Regexp
var IpSubnetRegex *regexp.Regexp
var IpV4Regex *regexp.Regexp
var IpV6Regex *regexp.Regexp
MaxU128 is the largest possible U128 value.
var RangeRegex *regexp.Regexp
var SubnetRegex *regexp.Regexp
var U128BitMasks = [...]U128{}/* 129 elements not displayed */
Copyright 2021 The Inet.Af AUTHORS. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file at https://github.com/inetaf/netaddr/blob/main/LICENSE
U128BitMasks are bitmasks with the topmost n bits of a 128-bit number, where n is the array index.
generated with https://play.golang.org/p/64XKxaUSa_9
var V4CidrRegex *regexp.Regexp
var V4IpCidrRegex *regexp.Regexp
var V4IpRangeRegex *regexp.Regexp
var V4IpSubnetRegex *regexp.Regexp
var V4RangeRegex *regexp.Regexp
var V4SubnetRegex *regexp.Regexp
var V6CidrRegex *regexp.Regexp
var V6IpCidrRegex *regexp.Regexp
var V6IpRangeRegex *regexp.Regexp
var V6IpSubnetRegex *regexp.Regexp
var V6RangeRegex *regexp.Regexp
var V6SubnetRegex *regexp.Regexp
Functions ¶
func CIDRsFromIP6RangeStrRaw ¶
CIDRsFromIP6RangeStrRaw returns a list of CIDR strings which cover the full range specified in the IP range string `rStr`.
`rStr` must be of any of these forms:
<ip_range_start>-<ip_range_end> <ip_range_start>,<ip_range_end>
func CIDRsFromIPRangeStrRaw ¶
CIDRsFromIPRangeStrRaw returns a list of CIDR strings which cover the full range specified in the IP range string `rStr`.
`rStr` must be of any of these forms:
<ip_range_start>-<ip_range_end> <ip_range_start>,<ip_range_end>
func DecimalStrToIP ¶
DecimalStrToIP converts a decimal string to an IP address
func GetInputFrom ¶
func GetInputFrom( inputs []string, stdin bool, file bool, op func(input string, inputType INPUT_TYPE) error, ) error
GetInputFrom retrieves input data from various sources and processes it using the provided operation. The operation is called for each input string with input type.
Usage: err := GetInputFrom(inputs, true, true, func(input string, inputType INPUT_TYPE) error { switch inputType { case INPUT_TYPE_IP: // Process IP here } return nil }, )
func IPListFromAllSrcs ¶
IPListFromAllSrcs returns a list of all IPs from all sources such as stdin, argument list and files.
func IPListFromCIDR ¶
IPListFromCIDR returns a list of IPs from a CIDR string.
func IPListFromCIDRs ¶
IPListFromCIDRs returns a list of IPs from a list of CIDRs in string form.
func IPListFromFile ¶
IPListFromFile returns a list of IPs found in a file.
func IPListFromFiles ¶
IPListFromFiles returns a list of IPs found in a list of files.
func IPListFromRange ¶
IPListFromRange returns a list of IPs from a start and end IP string.
func IPListFromRangeStr ¶
IPListFromRangeStr returns a list of IPs given a range string.
`rStr` must be of any of these forms:
<ip_range_start>-<ip_range_end> <ip_range_start>,<ip_range_end>
func IPListFromReader ¶
IPListFromReader returns a list of IPs after reading from a reader; the reader should have IPs per-line.
func IPListFromStdin ¶
IPListFromStdin returns a list of IPs from a stdin; the IPs should be 1 per line.
func IPListWriteAllFromFile ¶
IPListWriteFromFile returns a list of IPs found in a file.
func IPListWriteAllFromFiles ¶
IPListWriteFromFiles returns a list of IPs found in a list of files from all sources.
func IPListWriteAllFromReader ¶
IPListWriteFromReader returns a list of IPs after reading from a reader; the reader should have IPs per-line.
func IPListWriteAllFromStdin ¶
func IPListWriteAllFromStdin()
IPListWriteFromStdin returns a list of IPs from a stdin; the IPs should be 1 per line.
func IPListWriteFrom ¶
func IPListWriteFrom( inputs []string, stdin bool, ip bool, iprange bool, cidr bool, file bool, ) error
IPListFromWrite outputs a list of IPs from stdin and a list of inputs which are interpreted to contain IPs, IP ranges, IP CIDRs and files with IPs in them, all depending upon which flags are set.
func IPListWriteFromAllSrcs ¶
IPListFromAllSrcsWrite is the same as IPListFromWrite with all flags turned on.
func IPListWriteFromCIDR ¶
IPListFromCIDRWrite is the same as IPListFromCIDR with O(1) memory by discarding IPs after printing.
func IPListWriteFromCIDRs ¶
IPListFromCIDRsWrite outputs a list of IPs from a list of CIDRs in string form.
func IPListWriteFromFile ¶
IPListWriteFromSrcFile returns a list of IPs from selected sources found in a file.
func IPListWriteFromFiles ¶
IPListWriteFromFiles returns a list of IPs found in a list of files from select sources.
func IPListWriteFromIPRange ¶
IPListFromIPRangeWrite is the same as IPListFromRange with O(1) memory by discarding IPs after printing.
func IPListWriteFromIPRangeStr ¶
IPListFromIPRangeStrWrite outputs all IPs in an IP range.
`rStr` must be of any of these forms:
<ip_range_start>-<ip_range_end> <ip_range_start>,<ip_range_end>
func IPListWriteFromReader ¶
IPListWriteFromReader returns a list of IPs after reading from a reader from selected sources; the reader should have IPs per-line.
func IPListWriteFromStdin ¶
IPListWriteFromStdin returns a list of IPs from a stdin from selected sources; the IPs should be 1 per line.
func IPtoDecimalStr ¶
IPtoDecimalStr converts an IP address to a decimal string
func InputHelper ¶
func InputHelper(str string, op func(string, INPUT_TYPE) error) error
func NetAndHostMasks ¶
NetAndHostMasks returns network and host masks where the `size` most-significant bits are set to 1 and the rest set to 0 in the network mask, and the host mask is the bitwise-negation of the network mask.
func NetAndHostMasks6 ¶
NetAndHostMasks returns network and host masks where the `size` most-significant bits are set to 1 and the rest set to 0 in the network mask, and the host mask is the bitwise-negation of the network mask.
func ProcessStringsFromFile ¶
func ProcessStringsFromFile(filename string, op func(input string, inputType INPUT_TYPE) error) error
ProcessStringsFromFile reads strings from a file and passes it to op, one per line.
func ProcessStringsFromStdin ¶
func ProcessStringsFromStdin(op func(input string, inputType INPUT_TYPE) error) error
ProcessStringsFromStdin reads strings from stdin until an empty line is entered.
func RandIP4List ¶
RandIP4List returns a list of new randomly generated IPv4 addresses.
func RandIP4ListWrite ¶
RandIP4ListWrite prints a list of randomly generated IPv4 addresses.
func RandIP4Range ¶
RandIP4Range returns a list of randomly generated IPv4 addresses within the range specified by `IP4Range`.
note: `NewIP4Range` must be called before this function as this function assumes `IP4Range` provided to the function is a correct range.
func RandIP4RangeListWrite ¶
RandIP4RangeListWrite prints a list of randomly generated IPv4 addresses. `startIP` and `endIP` are the start & end IPs to generate IPs between. `n` is the number of IPs to generate. `noBogon`, if true, will ensure that none of the generated IPs are bogons. `unique`, if true, will ensure every IP generated is unique.
func RandIP6List ¶
RandIP6List returns a list of new randomly generated IPv6 addresses.
func RandIP6ListWrite ¶
RandIP6ListWrite prints a list of randomly generated IPv6 addresses.
func RandIP6Range ¶
func RandIP6Range(ipRange IP6RangeInt, noBogon bool) net.IP
RandIP6Range returns a list of randomly generated IPv6 addresses within the range specified by `IP6RangeInt`.
note: `NewIP6RangeInt` must be called before this function as this function assumes `IP6RangeInt` provided to the function is a correct range.
func RandIP6RangeListWrite ¶
RandIP6RangeListWrite prints a list of randomly generated IPv6 addresses. `startIP` and `endIP` are the start & end IPs to generate IPs between. `n` is the number of IPs to generate. `noBogon`, if true, will ensure that none of the generated IPs are bogons. `unique`, if true, will ensure every IP generated is unique.
func StrIsASNStr ¶
StrIsASNStr checks whether an ASN string really is an ASN of the form "asX" or "ASX" where "X" is the ASN's number.
func StrIsCIDR6Str ¶
StrIsCIDR6Str checks whether a string is in proper CIDR IPv6 form.
func StrIsCIDRStr ¶
StrIsCIDRStr checks whether a string is in proper CIDR form.
func StrIsIP6RangeStr ¶
StrIsIP6RangeStr checks whether a string is an IPv6 range string.
The string must be of any of these forms to be considered an IP range:
<ip_range_start>-<ip_range_end> <ip_range_start>,<ip_range_end>
func StrIsIP6Str ¶
StrIsIP6Str checks whether a string is an IPv6.
func StrIsIPRangeStr ¶
StrIsIPRangeStr checks whether a string is an IP range.
The string must be of any of these forms to be considered an IP range:
<ip_range_start>-<ip_range_end> <ip_range_start>,<ip_range_end>
func StrIsIPv4Str ¶
StrIsIPv4Str checks if the given string is an IPv4 address
func StrIsIPv6Str ¶
StrIsIPv6Str checks if the given string is an IPv6 address
func StringSliceRev ¶
func StringSliceRev(s []string)
StringSliceRev reverses the order of elements inside of a string slice.
Types ¶
type CIDR ¶
CIDR represens a Classless Inter-Domain Routing structure.
func NewCidrList ¶
NewCidrList returns a slice of sorted CIDR structures.
type INPUT_TYPE ¶
type INPUT_TYPE string
const ( INPUT_TYPE_IP INPUT_TYPE = "IP" INPUT_TYPE_IP_RANGE INPUT_TYPE = "IPRange" INPUT_TYPE_CIDR INPUT_TYPE = "CIDR" INPUT_TYPE_ASN INPUT_TYPE = "ASN" INPUT_TYPE_UNKNOWN INPUT_TYPE = "Unknown" )
type IP ¶
type IP uint32
IP is a numerical representation of an IPv4 address. The number must be in big-endian form.
func IPFromStdIP ¶
IPFromStdIP returns a new IPv4 address representation from the standard library's IP representation.
type IP4Range ¶
type IP4Range struct {
// contains filtered or unexported fields
}
IP4Range is a numerical representation of an IPv4 range.
type IP6 ¶
type IP6 struct {
N U128
}
IP6 is a 128-bit number representation of a IPv6 address in big endian byte order.
The number is internally represented as 2 64-bit numbers.
func IP6FromByteSlice ¶
IP6FromByteSlice is the same as IP6FromBytes but from a byte slice which may be longer than 16 bytes long.
<16 byte slice will cause a panic.
func IP6FromBytes ¶
IP6FromBytes returns a new IP6 given 16 bytes representing the 16 bytes of the IPv6 address in big-endian order.
func IP6FromIP4Bytes ¶
IP6FromIP4Bytes returns a new IP6 from the IPv4 address of bytes `a.b.c.d`.
func IP6FromStdIP ¶
IP6FromStdIP returns a new IP6 from a standard library `net.IP`, and whether the conversion succeeded.
func (IP6) Cmp ¶
Cmp compares `ip1` and `ip2` and returns:
- -1 if `ip1<ip2` - 0 if `ip1==ip2` - 1 if `ip1>ip2`
func (IP6) To16ByteSlice ¶
To16ByteSlice returns the 16-byte slice representation of an IPv6 address in big-endian byte order.
type IP6Range ¶
type IP6Range struct { // Start is the first IP in the IPv6 range. Start IP6 // End is the last IP in the IPv6 range. End IP6 }
IP6Range represents a range of IPv6 addresses [Start, End].
func GetBogonRange6 ¶
func GetBogonRange6() []IP6Range
GetBogonRange6 returns list of IPRange of all IPv6 bogon IPs.
func IP6RangeFromCIDR ¶
IP6RangeFromCIDR returns an IP6Range given a CIDR in string form.
func NewIP6Range ¶
IP6Range returns a new IPv6 address range given a start and end IPv6 address.
func (IP6Range) LargestIP6Subnet ¶
LargestIP6Subnet returns the largest subnet mask within this range.
func (IP6Range) ToIP6Subnets ¶
ToIP6Subnets returns a list of subnet masks which cover the full IP range.
type IP6RangeInt ¶
type IP6RangeInt struct {
// contains filtered or unexported fields
}
IP6Range is a numerical representation of an IPv6 range.
func NewIP6RangeInt ¶
func NewIP6RangeInt( startIP string, endIP string, ) (IP6RangeInt, error)
NewIP6RangeInt returns a new IP6RangeInt given the input start & end IPs.
note: starting and ending IPs must be valid IPv6 string formats.
type IP6RangeStr ¶
type IP6RangeStr struct { // Start is the first IP in the IPv6 range. Start string // End is the last IP in the IPv6 range. End string }
IP6RangeStr represents a range of IPv6 addresses [Start, End] in string form.
func IP6RangeStrFromCIDR ¶
func IP6RangeStrFromCIDR(cidrStr string) (IP6RangeStr, error)
IP6RangeStrFromCIDR returns the start and end IPv6 strings of a CIDR.
func IP6RangeStrFromStr ¶
func IP6RangeStrFromStr(r string) (IP6RangeStr, error)
IP6RangeStrFromStr returns the two IPv6 parts (start and end) of an IPv6 range string.
The string must be of any of these forms:
<ip_range_start>-<ip_range_end> <ip_range_start>,<ip_range_end>
func NewIP6RangeStr ¶
func NewIP6RangeStr(start string, end string) IP6RangeStr
NewIP6RangeStr returns a new IP range string given a start & end IP.
func (IP6RangeStr) String ¶
func (r IP6RangeStr) String() string
String returns the IPv6 range string as `<start>-<end>`.
func (IP6RangeStr) StringDelim ¶
func (r IP6RangeStr) StringDelim(d string) string
StringDelim is the same as String but allows a custom delimiter.
func (IP6RangeStr) ToCIDRs ¶
func (rStr IP6RangeStr) ToCIDRs() []string
ToCIDRs returns a list of CIDR strings which cover the full range specified in the IP range string `r`.
func (IP6RangeStr) ToIP6Range ¶
func (r IP6RangeStr) ToIP6Range() IP6Range
ToIP6Range converts the string form of the range into a numerical form.
type IP6Subnet ¶
type IP6Subnet struct { // NetBitCnt is the number of bits in the network part of the subnet. NetBitCnt uint32 // NetMask is the subnet mask of the network part of the subnet. NetMask U128 // HostBitCnt is the number of bits in the host part of the subnet. HostBitCnt uint32 // HostMask is the subnet mask of the host part of the subnet. HostMask U128 // LoIP is the big-endian representation of the lowest IP in the subnet. LoIP IP6 // HiIP is the big-endian representation of the highest IP in the subnet. HiIP IP6 }
IP6Subnet is the representation of a IPv6 subnet.
func IP6SubnetFromCidr ¶
IP6SubnetFromCidr converts a CIDR notation to IP6Subnet.
type IPRange ¶
type IPRange struct { // Start is the first IP in the IPv4 range. Start IP // End is the last IP in the IPv4 range. End IP }
IPRange represents a range of IPv4 addresses [Start, End].
func GetBogonRange4 ¶
func GetBogonRange4() []IPRange
GetBogonRange4 returns list of IPRange of all IPv4 bogon IPs.
func IPRangeFromCIDR ¶
IPRangeFromCIDR returns the start and end IPs in big endian byte order of a CIDR in string form.
func NewIPRange ¶
NewIPRange returns a new IP range given a start and end IP.
func (IPRange) LargestIPSubnet ¶
LargestIPSubnet returns the largest subnet mask within this range.
func (IPRange) ToIPSubnets ¶
ToIPSubnets returns a list of subnet masks which cover the full IP range.
type IPRangeStr ¶
type IPRangeStr struct { // Start is the first IP in the IPv4 range. Start string // End is the last IP in the IPv4 range. End string }
IPRangeStr represents a range of IPv4 addresses [Start, End] in string form.
func IPRangeStrFromCIDR ¶
func IPRangeStrFromCIDR(cidrStr string) (IPRangeStr, error)
IPRangeStrFromCIDR returns the start and end IP strings of a CIDR.
func IPRangeStrFromStr ¶
func IPRangeStrFromStr(r string) (IPRangeStr, error)
IPRangeStrFromStr returns the two IP parts (start and end) of an IP range string.
The string must be of any of these forms:
<ip_range_start>-<ip_range_end> <ip_range_start>,<ip_range_end>
func NewIPRangeStr ¶
func NewIPRangeStr(start string, end string) IPRangeStr
NewIPRangeStr returns a new IP range string given a start & end IP.
func (IPRangeStr) String ¶
func (r IPRangeStr) String() string
String returns the IP range string as `<start>-<end>`.
func (IPRangeStr) StringDelim ¶
func (r IPRangeStr) StringDelim(d string) string
StringDelim is the same as String but allows a custom delimiter.
func (IPRangeStr) ToCIDRs ¶
func (rStr IPRangeStr) ToCIDRs() []string
ToCIDRs returns a list of CIDR strings which cover the full range specified in the IP range string `r`.
func (IPRangeStr) ToIPRange ¶
func (r IPRangeStr) ToIPRange() IPRange
ToIPRange converts the string form of the range into a numerical form.
type IPSubnet ¶
type IPSubnet struct { // NetBitCnt is the number of bits in the network part of the subnet. NetBitCnt uint32 // NetMask is the subnet mask of the network part of the subnet. NetMask uint32 // HostBitCnt is the number of bits in the host part of the subnet. HostBitCnt uint32 // HostMask is the subnet mask of the host part of the subnet. HostMask uint32 // LoIP is the big-endian representation of the lowest IP in the subnet. LoIP IP // HiIP is the big-endian representation of the highest IP in the subnet. HiIP IP }
IPSubnet is the representation of a IPv4 subnet.
func IPSubnetFromCidr ¶
IPSubnetFromCidr converts a CIDR notation to IPSubnet.
type U128 ¶
U128 is an unsigned 128-bit number type in big-endian form.
The endianness of `Hi` and `Lo` themselves is machine-dependent.
var ZeroU128 U128
ZeroU128 is a zero-valued U128.
func (U128) Add ¶
Add returns `v1 + v2` and any carry on overflow. The carry is guaranteed to be 0 or 1.
func (U128) Add64 ¶
Add64 returns `v1 + v2` and any carry on overflow. The carry is guaranteed to be 0 or 1.
func (U128) AddOne ¶
AddOne returns `v1 + 1`. If overflow occurred, then IsZero will be true on the result.
func (U128) ClearBitsFrom ¶
ClearBitsFrom clears all bits from and including the `i`th bit, where `i` starts from 0 which refers to the most-significant bit.
func (U128) ClearBitsUpto ¶
ClearBitsUpto clears all bits from the most-significant bit up to the `ith` bit, where `i` starts from 0 which refers to the most-significant bit.
func (U128) Cmp ¶
Cmp compares `v1` and `v2` and returns:
- -1 if `v1<v2` - 0 if `v1==v2` - 1 if `v1>v2`
func (U128) LeadingZeros ¶
LeadingZeros returns the number of leading zero bits in `v`. Returns 128 for `v == 0`.
func (U128) Len ¶
Len returns the minimum number of bits required to represent `v`. Returns 0 for `v == 0`.
func (U128) OnesCount ¶
OnesCount returns the number of "1" bits in `v`. This is also sometimes referred to as the "population count" of `v`.
func (U128) ReverseBytes ¶
ReverseBytes returns a version of `v` with all bytes reversed.
func (U128) SetBitsFrom ¶
SetBitsFrom sets all bits from and including the `i`th bit, where `i` starts from 0 which refers to the most-significant bit.
func (U128) SetBitsUpto ¶
SetBitsUpto sets all bits from the most-significant bit up to the `ith` bit, where `i` starts from 0 which refers to the most-significant bit.
func (U128) Sub ¶
Sub returns `v1 - v2` and any borrow on underflow. The borrow is guaranteed to be 0 or 1.
func (U128) Sub64 ¶
Sub64 returns `v1 - v2` and any borrow on underflow. The borrow is guaranteed to be 0 or 1.
func (U128) SubOne ¶
SubOne returns `v1 - 1`. If underflow occurred, then IsMax will be true on the result.
func (U128) TrailingZeros ¶
TrailingZeros returns the number of trailing zero bits in v. Returns 128 for `v == 0`.
Source Files ¶
- asn_str.go
- bogon.go
- cidr.go
- errors.go
- file.go
- init.go
- ip.go
- ip6.go
- ip6_range.go
- ip6_range_str.go
- ip6_str.go
- ip6_subnet.go
- ip6_subnet_str.go
- ip_conversions.go
- ip_list.go
- ip_list_write.go
- ip_math.go
- ip_range.go
- ip_range_str.go
- ip_str.go
- ip_subnet.go
- ip_subnet_str.go
- regex.go
- string_slice.go
- u128.go
- utils_input.go