I wish to redirect traffic based on hundreds of IP ranges (which results in several millions of individual IP addresses) and looking for the best way to do this (best = resulting in most optimal redirect speeds).
1. default method is to use a Condition node but this does not support IP ranges so requires the individual IP addresses (with here or there using the * wildcard whenever possible to bring down total number of records). Have not set this up yet but doubt that condition nodes are optimal when holding millions of values.
2. or use a PHP node which scans a custom database table that holds the individual IP addresses.
this is probably the most straightforward, though there must be a smarter way which allows to store IP ranges and efficiently scan those instead of the individual IP addresses.
3. any other methods worth considering?
Have raised this topic with Funnelflux support, but wanted to see if perhaps anyone has experience with this.
I could certainly see how that would be useful! Just wondering - did you find out anything after speaking with Funnelflux support?
Not being very technically-oriented, I'd have no idea how to implement something like that. Would probably just brute-force this by setting up one camp targeting each IP range - which would probably result in the fastest redirect speeds. But it would require that the traffic source allow IP targeting, and having to set up hundreds of campaigns can be time-consuming (unless you automate using API).
Amy
This may be of help - PHP to check an IP against an IP range.
https://github.com/cloudflare/CloudF...p_in_range.php
It's a bit complex, though - another simpler version is
function CheckIpRange($ip, $min, $max) {
return (ip2long($min); < ip2long($ip) && ip2long($ip) < ip2long($max));
}
update - in case anyone else ever needs this:
- I initially created a custom database table to store the ranges, and simply scanned that table with a Funnelflux PHP node.
It worked fine and I really didn't see any issues with it, but still it didn't feel like the best possible solution (i.e. having to create a new DB connection / execute query / close DB connection on each redirect).
- so I came across this article explaining how to build your own maxmind database files:
https://blog.maxmind.com/2015/09/29/...un-and-profit/
It requires using Perl which ended up being very easy even though I'd never seen or touched Perl before. Basically I just followed their instructions and ended up with my custom mmdb (maxmind database) file which I could then easily access with a Funnelflux PHP node using the maxmind API.
Feel free to DM me for more info!
Cheers,