This commit is contained in:
crusader 2017-11-17 19:12:50 +09:00
parent 4bf418325b
commit c8c6521c25
3 changed files with 27 additions and 12 deletions

View File

@ -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
}

View File

@ -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

View File

@ -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
}