diff --git a/net/cidr/range.go b/net/cidr/range.go index e5c9abd..1d76987 100644 --- a/net/cidr/range.go +++ b/net/cidr/range.go @@ -31,7 +31,9 @@ type CIDRRanger interface { Contains(ip net.IP) bool First() net.IP Last() net.IP - Range() []net.IP + Range(exclude []net.IP) []net.IP Broadcast() net.IP Network() net.IP + Next(ip net.IP) net.IP + Previous(ip net.IP) net.IP } diff --git a/net/cidr/range_v4.go b/net/cidr/range_v4.go index ae814fc..27fe60d 100644 --- a/net/cidr/range_v4.go +++ b/net/cidr/range_v4.go @@ -24,7 +24,7 @@ func (cr *cidrRangeIPv4) Last() net.IP { return cr.Previous(bIP) } -func (cr *cidrRangeIPv4) Range() []net.IP { +func (cr *cidrRangeIPv4) Range(exclude []net.IP) []net.IP { fIP := cr.First() if nil == fIP { return nil @@ -35,8 +35,21 @@ func (cr *cidrRangeIPv4) Range() []net.IP { } fNum := converter.IPv4ToInt(fIP.To4()) lNum := converter.IPv4ToInt(lIP.To4()) + + exs := make([]int32, 0) + if nil != exclude { + for _, ex := range exclude { + exs = append(exs, converter.IPv4ToInt(ex.To4())) + } + } + r := make([]net.IP, 0) for i := fNum; i <= lNum; i++ { + for _, exN := range exs { + if exN == i { + continue + } + } r = append(r, converter.IntToIPv4(i)) } return r diff --git a/net/cidr/range_v6.go b/net/cidr/range_v6.go index 4ec8804..fe5ecfa 100644 --- a/net/cidr/range_v6.go +++ b/net/cidr/range_v6.go @@ -11,29 +11,29 @@ func (cr *cidrRangeIPv6) Contains(ip net.IP) bool { } func (cr *cidrRangeIPv6) First() net.IP { - + return nil } func (cr *cidrRangeIPv6) Last() net.IP { - + return nil } -func (cr *cidrRangeIPv6) Range() []net.IP { - +func (cr *cidrRangeIPv6) Range(exclude []net.IP) []net.IP { + return nil } func (cr *cidrRangeIPv6) Broadcast() net.IP { - + return nil } func (cr *cidrRangeIPv6) Network() net.IP { - + return nil } -func (cr *cidrRangeIPv6) Next(ip net.IP) { - +func (cr *cidrRangeIPv6) Next(ip net.IP) net.IP { + return nil } -func (cr *cidrRangeIPv6) Previous(ip net.IP) { - +func (cr *cidrRangeIPv6) Previous(ip net.IP) net.IP { + return nil }