With my continued battle of blocking spammers from Nigeria I've blocked the country code in my htaccess file using GeoIP but some still manage to get through. To add another layer I want to iterate through the following list of IP ranges from Nigeria and block them:
41.75.192.0 41.75.207.255
41.138.160.0 41.138.191.255
41.139.64.0 41.139.127.255
41.155.0.0 41.155.127.255
41.184.0.0 41.184.255.255
41.189.0.0 41.189.31.255
41.190.0.0 41.190.31.255
41.203.64.0 41.203.95.255
41.203.96.0 41.203.127.255
41.204.224.0 41.204.255.255
41.205.160.0 41.205.191.255
41.206.0.0 41.206.31.255
41.206.224.0 41.206.255.255
41.211.192.0 41.211.255.255
41.216.160.0 41.216.175.255
41.217.0.0 41.217.127.255
41.219.128.0 41.219.191.255
41.219.192.0 41.219.255.255
41.220.64.0 41.220.79.255
41.221.112.0 41.221.127.255
41.221.160.0 41.221.175.255
62.173.32.0 62.173.63.255
62.193.160.0 62.193.191.255
80.248.0.0 80.248.15.255
80.250.32.0 80.250.47.255
81.18.32.0 81.18.47.255
82.128.0.0 82.128.127.255
195.166.224.0 195.166.255.255
196.1.176.0 196.1.191.255
196.29.208.0 196.29.223.255
196.45.48.0 196.45.63.255
196.45.192.0 196.45.255.255
196.200.0.0 196.200.15.255
196.200.64.0 196.200.79.255
196.200.112.0 196.200.127.255
196.207.0.0 196.207.15.255
196.220.0.0 196.220.31.255
212.100.64.0 212.100.95.255
217.14.80.0 217.14.95.255
217.117.0.0 217.117.15.255
Using the following code to check each range is there a more efficient method or way of doing this?
$range_start = ip2long("41.75.192.0");
$range_end = ip2long("41.75.207.255");
$ip = ip2long($_SERVER['REMOTE_ADDR']);
if ($ip >= $range_start && $ip <= $range_end) {
// blocked
}