ipv4range

package module
v0.0.0-...-4c93fd7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 12, 2018 License: MIT Imports: 6 Imported by: 0

README

ipv4range

Fast IPv4 address range matcher.

Install

go get -u github.com/okzk/ipv4range

Example

matcher, _ := ipv4range.NewMatcher("10.10.0.0/16", "10.20.0.0/16", "10.30.0.0/16")

if matcher.Match("10.10.10.10") {
    // do something	
}

License

MIT

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Matcher

type Matcher struct {
	// contains filtered or unexported fields
}

Matcher provides fast IPv4 address matching

func NewMatcher

func NewMatcher(rangeList ...string) (*Matcher, error)

NewMatcher creates a Matcher with the ip ranges. IP range expression should be one of following formats:

  • CIDR(ex. "10.0.0.0/8")
  • raw IP(ex. "127.0.0.1")
  • IP range(ex. "192.168.1.1 - 192.168.1.100")

func (*Matcher) Match

func (m *Matcher) Match(ipStr string) bool

Match reports whether the Matcher's ip ranges includes ip

Example
matcher, _ := NewMatcher("10.10.0.0/16", "10.20.0.0/16", "10.30.0.0/16")

fmt.Println(matcher.Match("10.10.10.10"))
fmt.Println(matcher.Match("10.100.100.100"))
Output:
true
false

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL