This npm package is used to check if a certain IP came from Cloudflare. The list of Cloudflare IPs is updated every day.
npm install https://github.com/rrainn/cloudflare-ip-check.git
const cloudflareIPCheck = require("cloudflare-ip-check");
Array of strings representing every Cloudflare IP range.
console.log(cloudflareIPCheck.cloudflareIPs);
Array of strings representing every v4 Cloudflare IP range.
console.log(cloudflareIPCheck.v4cloudflareIPs);
Array of strings representing every v6 Cloudflare IP range.
console.log(cloudflareIPCheck.v6cloudflareIPs);
Check if an IP is from Cloudflare, returns a boolean representing if an IP is from Cloudflare.
console.log(cloudflareIPCheck.isFromCloudflare("0.0.0.0")); // false
console.log(cloudflareIPCheck.isFromCloudflare("173.245.48.2")); // true
This is an Express.js middleware function that can be used to check if an IP is from Cloudflare.
app.use(cloudflareIPCheck.middleware());
You can optionally pass in an object representing the configuration of the middleware.
app.use(cloudflareIPCheck.middleware({
"error": {
"status": 403,
"send": "Forbidden"
}
}));
If no configuration is passed in, it will return 403 "Forbidden" if the IP is not from Cloudflare.