Documentation
¶
Overview ¶
Package ipsearch provides a simple way to search for IP addresses in a
Index ¶
- func GetIPSegment(ip string, segment int) uint8
- func IPCIDRRange(cidr string) (uint32, uint32)
- func IPInCIDR(ip string, cidr string) bool
- func IPIntToStr(ip uint32) string
- func IPStrToInt(ipStr string) uint32
- func ReadFile(filename string) ([]string, error)
- func ReadFileFromURL(url string) ([]string, error)
- type IPRange
- type IPRangeList
- type IPRangeMapList
- func (m IPRangeMapList) Append(ipRange *IPRange)
- func (m IPRangeMapList) AppendBatch(ipRanges []*IPRange)
- func (m IPRangeMapList) InsertSorted(ipRange *IPRange)
- func (m IPRangeMapList) InsertSortedCIDRs(ipRanges []*IPRange)
- func (m IPRangeMapList) Search(ipStr string) *IPRange
- func (m IPRangeMapList) Sort()
- type IPSearch
- type RangeType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetIPSegment ¶
GetIPSegment returns the segment of an IP address.
func IPCIDRRange ¶
IPCIDRRange returns the start and end IP addresses for a CIDR range.
func IPIntToStr ¶
IPIntToStr converts an integer IP address to a string.
func IPStrToInt ¶
IPStrToInt converts a string IP address to an integer.
func ReadFileFromURL ¶
ReadFileFromURL from a URL and returns a slice of strings, one for each line.
Types ¶
type IPRange ¶
type IPRange struct {
// contains filtered or unexported fields
}
IPRange represents an IPv4 CIDR range.
func NewIPRange ¶
NewIPRange creates a new IPRange.
func NewIPRangeSlice ¶
NewIPRangeSlice creates a new slice of IPRange.
type IPRangeList ¶
type IPRangeList []*IPRange
IPRangeList is a list of IPv4 CIDR ranges.
func NewIPRangeList ¶
func NewIPRangeList(lines []string, rangeType RangeType) IPRangeList
NewIPRangeList creates a new list of IPv4 CIDR ranges.
func (*IPRangeList) Append ¶
func (list *IPRangeList) Append(ip *IPRange)
Append adds a IPv4 range to the list.
func (*IPRangeList) InsertSorted ¶
func (list *IPRangeList) InsertSorted(ip *IPRange)
InsertSorted inserts a IPv4 range to the list, keeping the list sorted.
func (*IPRangeList) Len ¶
func (list *IPRangeList) Len() int
Len returns the length of the list of IPv4 CIDR ranges.
func (*IPRangeList) Range ¶
func (list *IPRangeList) Range() string
Range returns a string representation of the list of IPv4 ranges.
func (*IPRangeList) Search ¶
func (list *IPRangeList) Search(ipStr string) *IPRange
Search search if an IP address is in the list.
func (*IPRangeList) String ¶
func (list *IPRangeList) String() string
String returns a string representation of the list of IPv4 CIDR ranges.
type IPRangeMapList ¶
type IPRangeMapList map[uint8]*IPRangeList
IPRangeMapList is a map of lists of IPv4 CIDR ranges.
func NewIPRangeMapList ¶
func NewIPRangeMapList() IPRangeMapList
NewIPRangeMapList creates a new map of lists of IPv4 CIDR ranges.
func (IPRangeMapList) Append ¶
func (m IPRangeMapList) Append(ipRange *IPRange)
Append adds an IPv4 CIDR range to the map of lists of IPv4 CIDR ranges.
func (IPRangeMapList) AppendBatch ¶
func (m IPRangeMapList) AppendBatch(ipRanges []*IPRange)
AppendBatch adds a list of IPv4 CIDR ranges to the map of lists of IPv4 CIDR ranges.
func (IPRangeMapList) InsertSorted ¶
func (m IPRangeMapList) InsertSorted(ipRange *IPRange)
InsertSorted inserts a IPv4 CIDR range to the map of lists of IPv4 CIDR ranges, keeping the lists sorted.
func (IPRangeMapList) InsertSortedCIDRs ¶
func (m IPRangeMapList) InsertSortedCIDRs(ipRanges []*IPRange)
InsertSortedCIDRs inserts a list of IPv4 CIDR ranges to the map of lists of IPv4 CIDR ranges, keeping the lists sorted.
func (IPRangeMapList) Search ¶
func (m IPRangeMapList) Search(ipStr string) *IPRange
Search search if an IP address is in the map of lists.
func (IPRangeMapList) Sort ¶
func (m IPRangeMapList) Sort()
Sort sorts the map of lists of IPv4 CIDR ranges.
type IPSearch ¶
type IPSearch struct {
// contains filtered or unexported fields
}
IPSearch is a struct that contains a map of IP ranges.
func NewIPSearch ¶
NewIPSearch creates a new IPSearch struct.
func NewIPSearchWithFile ¶
NewIPSearchWithFile creates a new IPSearch struct from a file.
func NewIPSearchWithFileFromURL ¶
NewIPSearchWithFileFromURL creates a new IPSearch struct from a URL.