NSObjects / iprange

IP range is a set of IP addresses. Both IPv4 and IPv6 are supported.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

iprange

This package helps you to work with IP ranges,Both IPv4 and IPv6 are supported.

IP range doesn't contain network and broadcast IP addresses if the format is IPv4 CIDR, IPv4 subnet mask or IPv6 CIDR.

Installation

Install iprange with go mod

  go get github.com/NSObjects/iprange  

Supported formats

  • IPv4 address (192.0.2.1)
  • IPv4 range (192.0.2.0-192.0.2.10)
  • IPv4 CIDR (192.0.2.0/24)
  • IPv4 subnet mask (192.0.2.0/255.255.255.0)
  • IPv6 address (2001:db8::1)
  • IPv6 range (2001:db8::-2001:db8::10)
  • IPv6 CIDR (2001:db8::/64)

Usage/Examples

Range

parseRange, err := iprange.ParseRange("192.0.2.1-192.0.2.10")
if err != nil {
	panic(err)
}
fmt.Println(parseRange.Ips())
}

CIDR

parseRange, err := iprange.ParseRange("192.0.2.1/24")
if err != nil {
	panic(err)
}
fmt.Println(parseRange.Ips())
}

subnet mask

parseRange, err := iprange.ParseRange("192.0.2.1/255.255.255.255")
if err != nil {
	panic(err)
}
fmt.Println(parseRange.Ips())
}

About

IP range is a set of IP addresses. Both IPv4 and IPv6 are supported.

License:GNU General Public License v3.0


Languages

Language:Go 100.0%