Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rrainn/cloudflare-ip-check
https://github.com/rrainn/cloudflare-ip-check
Last synced: 23 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/rrainn/cloudflare-ip-check
- Owner: rrainn
- License: mit
- Created: 2022-08-13T15:59:50.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-08-14T15:47:26.000Z (over 2 years ago)
- Last Synced: 2024-12-09T16:55:55.787Z (30 days ago)
- Language: JavaScript
- Size: 11.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cloudflare-ip-check
## Summary
This npm package is used to check if a certain IP came from Cloudflare. The list of Cloudflare IPs is updated every day.
## Install
```
npm install https://github.com/rrainn/cloudflare-ip-check.git
```## Usage
```js
const cloudflareIPCheck = require("cloudflare-ip-check");
```### cloudflareIPs
Array of strings representing every Cloudflare IP range.
```js
console.log(cloudflareIPCheck.cloudflareIPs);
```### v4cloudflareIPs
Array of strings representing every v4 Cloudflare IP range.
```js
console.log(cloudflareIPCheck.v4cloudflareIPs);
```### v6cloudflareIPs
Array of strings representing every v6 Cloudflare IP range.
```js
console.log(cloudflareIPCheck.v6cloudflareIPs);
```### isFromCloudflare(ip)
Check if an IP is from Cloudflare, returns a boolean representing if an IP is from Cloudflare.
```js
console.log(cloudflareIPCheck.isFromCloudflare("0.0.0.0")); // false
console.log(cloudflareIPCheck.isFromCloudflare("173.245.48.2")); // true
```### middleware([configuration])
This is an Express.js middleware function that can be used to check if an IP is from Cloudflare.
```js
app.use(cloudflareIPCheck.middleware());
```You can optionally pass in an object representing the configuration of the middleware.
```js
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.