coercive/botkicker

Coercive Security BotKicker

0.0.55 2024-09-27 19:34 UTC

README

基于黑名单的简单检测

获取

composer require coercive/botkicker

列出信息

警告信息

由于检测范围过大,一些术语被放置在模糊列表中。您可以在每个列表目录中找到这些模糊文件。(进行中)

踢出系统

基础知识

use  Coercive\Security\BotKicker\UserAgentKicker;

# Get Instance
$kicker = new UserAgentKicker; // or othe kicker

# Load a default list
$kicker->loadCoerciveLists();
# or load custom list...

# Basic bot detection
if(!$kicker->detect()->getStatus()) {
	echo 'a bot is detected';
}
else {
    # True if in whitelist or not in blacklist
}

您可以检测是否需要UA robots.txt

if($kicker->isRobotsTxtRequested()) { /* do something */ }

(允许/不允许)空

# You can (dis)allow empty current detection
$kicker->allowEmpty( true | false );

仅 HostKicker

您可以从IP列表中检测主机名

# HostKicker only
$kicker = new HostKicker;

# Set your ip list
$kicker->setHostFromIp( [
	'xxx.xx.xx.x',
	'yy.yyy.y.y',
	'...',
] );

仅 IpKicker

您可以使用IpKicker的自动IP检测

# Get auto Ip list detection
$list = (new IpKicker)->getCurrents();

# Set auto ip list
$kicker = new HostKicker;
$kicker->setHostFromIp($list);

IpKicker现在可以检测Facebookbot和Bingbot

# Get auto Ip list detection
$ipk = new IpKicker;

$list = $ipk->getFacebookList();

$list = $ipk->isBing('157.55.39.1', true | false); # Linux Host cmd (true) / NsLookUp (false)

在自定义元素上触发

# Example of custom datas
$datas = ['bot1', 'bot2', 'bot3'];

# Override auto detection
$kicker->setCurrents($datas);

# Show detection result
$status = $kicker->detect();
var_dump( $status->getList() );

处理自定义列表

您可以设置自己的列表(数组格式)

$kicker->setBlackList([
	'bad',
	'bad too'
]);
$kicker->setWhiteList([
	'good',
	'good too'
]);

或从文件(txt brut格式)

$kicker->setBlackListFromFiles([
	'/path/file1',
	'/path/file2'
]);
$kicker->setWhiteListFromFiles([
	'/path/file1',
	'/path/file2'
]);

如果已加载一些列表,您可以添加一些项目

$kicker->addToBlackList([
	'bad',
	'bad too'
]);
$kicker->addToWhiteList([
	'good',
	'good too'
]);

处理要验证的自定义元素

# Example of custom datas
$datas = ['bot1', 'bot2', 'bot3'];

# Override auto detection
$kicker->setCurrents($datas);

# Show detection result
$status = $kicker->detect();

var_dump( $status->getStatus() ); # bool if ok or not
var_dump( $status->getList() ); # array list of match elements
var_dump( $status->getCurrents() ); # array current datas

主机 / Ns 查找

从IP获取域名列表

use Coercive\Security\BotKicker\HostLookUp;
use Coercive\Security\BotKicker\NsLookUp;

$look = new HostLookUp;
# OR
$look = new NsLookUp;

$array = $look->getDomains('111.22.33.4');

从域名获取IP列表

use Coercive\Security\BotKicker\HostLookUp;
use Coercive\Security\BotKicker\NsLookUp;

$look = new HostLookUp;
# OR
$look = new NsLookUp;

$array = $look->getIps('www.example.com.');

匹配项目

use Coercive\Security\BotKicker\HostLookUp;
use Coercive\Security\BotKicker\NsLookUp;

$look = new HostLookUp;
# OR
$look = new NsLookUp;

# Match ip > domain
$array = $look->match('111.22.33.4', 'www.example.com.');

# OR mactch with reverse (match ip > domain first and domain > ip after)
$array = $look->match('111.22.33.4', 'www.example.com.', true);