Skip to content

Instantly share code, notes, and snippets.

@lwc
Created February 24, 2017 04:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lwc/b8d48f944436bbc7ccb4c58e04cb7122 to your computer and use it in GitHub Desktop.
Save lwc/b8d48f944436bbc7ccb4c58e04cb7122 to your computer and use it in GitHub Desktop.
Test for cloudflare IP
package main
import (
"net"
"os"
"fmt"
)
var cidrs = []string{
"103.21.244.0/22",
"103.22.200.0/22",
"103.31.4.0/22",
"104.16.0.0/12",
"108.162.192.0/18",
"131.0.72.0/22",
"141.101.64.0/18",
"162.158.0.0/15",
"172.64.0.0/13",
"173.245.48.0/20",
"188.114.96.0/20",
"190.93.240.0/20",
"197.234.240.0/22",
"198.41.128.0/17",
"199.27.128.0/21",
}
func main() {
host := os.Args[1]
ips, _ := net.LookupIP(host)
for _, cidr := range cidrs {
_, ipNet, _ := net.ParseCIDR(cidr)
for _, ip := range ips {
if ipNet.Contains(ip) {
fmt.Printf("%s found in a cloudflare ip range\n", ip)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment