Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fixed .0 addresses not recognized as part of subnet #31

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions check.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,9 @@ func isCloudflare(ip net.IP) bool {
continue
}

hosts, err := hosts(c)
if err != nil {
continue
}

for _, host := range hosts {
if host == ip.String() {
return true
}
_, cidrNet, _ := net.ParseCIDR(c)
if cidrNet.Contains(ip) {
return true
}
}
return false
Expand Down
29 changes: 0 additions & 29 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,6 @@ func show(host string, ip net.IP, mode bool) {
}
}

func inc(ip net.IP) {
for j := len(ip) - 1; j >= 0; j-- {
ip[j]++
if ip[j] > 0 {
break
}
}
}

func hosts(cidr string) ([]string, error) {
ip, ipnet, err := net.ParseCIDR(cidr)
if err != nil {
return nil, err
}

var ips []string
for ip := ip.Mask(ipnet.Mask); ipnet.Contains(ip); inc(ip) {
ips = append(ips, ip.String())
}

lenIPs := len(ips)
switch {
case lenIPs < 2:
return ips, nil
default:
return ips[1 : len(ips)-1], nil
}
}

func isStdin() bool {
f, e := os.Stdin.Stat()
if e != nil {
Expand Down