public static function HttpblEvaluator::makeBannedHosts in http:BL 8
Quickly make up to 255 evaluated and banned hosts of a certain expire time.
@internal $count ---------------------------------------------------------------------------
Example uses: Execute in devel/php to make dummy hosts.
Also executable in drush as "drush mbb".
use Drupal\httpbl\Utility\Makehosts; Makehosts::makeBannedHosts(); // Use defaults to create 255 blacklisted and banned hosts that will expire in 5 minutes. Useful for testing Cron.
use Drupal\httpbl\Utility\Makehosts; Makehosts::makeBannedHosts(50,60, '129.0.8.'); Make 50 blacklisted and banned hosts that will last one minute.
Parameters
int $max The number of hosts to be generated.:
int $offset The time from now the host should expire.:
string $pattern The pattern used for IP addresses.:
File
- src/
HttpblEvaluator.php, line 665
Class
- HttpblEvaluator
- HttpblEvaluator evaluates visitor/host page requests.
Namespace
Drupal\httpblCode
public static function makeBannedHosts($max = 255, $offset = 300, $pattern = '127.1.8.') {
$limit = 255;
$max <= $limit ?: ($max = $limit);
$count = 1;
$max = $max + 1;
$status = 1;
while ($count < $max) {
$ip = $pattern . $count;
$host = Host::create([
'host_ip' => $ip,
'host_status' => $status,
'expire' => \Drupal::time()
->getRequestTime() + $offset,
'source' => t(HTTPBL_DRUSH_CREATED_BANNED),
]);
$host
->save();
$banManager = \Drupal::service('ban.ip_manager');
$banManager
->banIp($host
->label());
$logTrapper = \Drupal::service('httpbl.logtrapper');
$logTrapper
->trapDebug('@ip test banned host created with makeBannedHosts().', [
'@ip' => $ip,
]);
$count++;
}
}