iprange

package module
v0.0.0-...-08fbe35 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2015 License: MIT Imports: 2 Imported by: 0

README

go-iprange

Build Status Coverage Status

Installation

go get github.com/pocke/go-iprange

Usage

One IP.

r, err := iprange.New("192.168.0.1")
if err != nil {
  panic(err)
}
r.IncludeStr("192.168.0.1") // => true
r.IncludeStr("192.168.0.2") // => false

IP with CIDR.

r, err = iprange.New("192.168.0.0/24")
if err != nil {
  panic(err)
}
r.IncludeStr("192.168.0.1") // => true
r.IncludeStr("192.168.0.2") // => true
r.IncludeStr("192.168.1.2") // => false

Comma sepalated IP.

r, err = iprange.New("192.168.0.0/24,172.0.0.0/16,192.168.1.1")
if err != nil {
  panic(err)
}
r.IncludeStr("192.168.0.1") // => true
r.IncludeStr("192.168.1.1") // => true
r.IncludeStr("172.0.10.11") // => true

IPv6

r, err = iprange.New("2001:0db8:bd05:01d2:288a:1fc0:0001:10ee")
if err != nil {
  panic(err)
}
r.IncludeStr("2001:0db8:bd05:01d2:288a:1fc0:0001:10ee") // => false
r.IncludeStr("192.168.0.1") // => false

With TCP connection.

r, err := iprange.New("192.168.0.1")
if err != nil {
  panic(err)
}

l, _ := net.ListenTCP("tcp", addr)
conn, err := l.Accept()
r.IncludeConn(conn)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Range

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

func New

func New(ipStr string) (*Range, error)

func (*Range) Include

func (r *Range) Include(addr net.IP) bool

func (*Range) IncludeStr

func (r *Range) IncludeStr(addr string) bool

func (*Range) InlucdeConn

func (r *Range) InlucdeConn(conn net.Conn) bool

Jump to

Keyboard shortcuts

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