1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* _ ___ ___ ___ ___ |
5
|
|
|
* __ _| |__ _ _ ___ ___|_ _| _ \ \| _ ) |
6
|
|
|
* / _` | '_ \ || (_-</ -_)| || _/ |) | _ \ |
7
|
|
|
* \__,_|_.__/\_,_/__/\___|___|_| |___/|___/ |
8
|
|
|
* |
9
|
|
|
* This file is part of Kristuff\AbuseIPDB. |
10
|
|
|
* |
11
|
|
|
* (c) Kristuff <[email protected]> |
12
|
|
|
* |
13
|
|
|
* For the full copyright and license information, please view the LICENSE |
14
|
|
|
* file that was distributed with this source code. |
15
|
|
|
* |
16
|
|
|
* @version 0.9.20 |
17
|
|
|
* @copyright 2020-2022 Kristuff |
18
|
|
|
*/ |
19
|
|
|
namespace Kristuff\AbuseIPDB; |
20
|
|
|
|
21
|
|
|
use Kristuff\Mishell\Console; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Trait CheckBlock |
25
|
|
|
*/ |
26
|
|
|
trait CheckBlockTrait |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Prints IP detail |
30
|
|
|
* |
31
|
|
|
* @access protected |
32
|
|
|
* @static |
33
|
|
|
* @param object $response |
34
|
|
|
* |
35
|
|
|
* @return void |
36
|
|
|
*/ |
37
|
|
|
protected static function printCheckBlockDetail(object $response): void |
38
|
|
|
{ |
39
|
|
|
self::printResult(Console::pad(' Network Address:', 23), $response->data->networkAddress, 'lightyellow'); |
40
|
|
|
self::printResult(Console::pad(' Netmask:', 23), $response->data->netmask, 'lightyellow'); |
41
|
|
|
self::printResult(Console::pad(' Min Address:', 23), $response->data->minAddress, 'lightyellow'); |
42
|
|
|
self::printResult(Console::pad(' Max Address:', 23), $response->data->maxAddress, 'lightyellow'); |
43
|
|
|
self::printResult(Console::pad(' Possible Hosts:', 23), $response->data->numPossibleHosts, 'lightyellow'); |
44
|
|
|
self::printResult(Console::pad(' Address SpaceDesc:', 23), $response->data->addressSpaceDesc, 'lightyellow'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Prints reported IP |
49
|
|
|
* |
50
|
|
|
* @access protected |
51
|
|
|
* @static |
52
|
|
|
* @param object $response |
53
|
|
|
* @param int $maxAge |
54
|
|
|
* @param int $limit |
55
|
|
|
* |
56
|
|
|
* @return void |
57
|
|
|
*/ |
58
|
|
|
protected static function printCheckBlockReportedIP(object $response, int $maxAge, int $limit): void |
59
|
|
|
{ |
60
|
|
|
$nbReports = isset($response->data->reportedAddress) ? count($response->data->reportedAddress) : 0; |
61
|
|
|
|
62
|
|
|
if ($nbReports > 0) { |
63
|
|
|
self::printResult(Console::pad(' Reported addresses:', 23), $nbReports, 'lightyellow'); |
64
|
|
|
$numberDiplayedReports = 0; |
65
|
|
|
|
66
|
|
|
foreach ($response->data->reportedAddress as $report){ |
67
|
|
|
$score = empty($report->abuseConfidenceScore) ? 0 : $report->abuseConfidenceScore; |
68
|
|
|
$defaultColor = self::getScoreColor($score); // color based on score |
69
|
|
|
|
70
|
|
|
$line = Console::text(' →', $defaultColor); |
71
|
|
|
$line .= self::printResult(' IP: ', $report->ipAddress, $defaultColor, '', false); |
72
|
|
|
$line .= self::printResult(' Country: ', $report->countryCode , $defaultColor, '', false); |
73
|
|
|
$line .= Console::text(' | Confidence score: ', 'white'); |
74
|
|
|
$line .= self::getScoreBadge($score); |
75
|
|
|
$line .= self::printResult(' Total reports: ', $report->numReports, $defaultColor, '', false); |
76
|
|
|
$line .= self::printResult(' Last reported at: ', self::getDate($report->mostRecentReport), $defaultColor, '', false); |
77
|
|
|
Console::log($line); |
78
|
|
|
|
79
|
|
|
// counter |
80
|
|
|
$numberDiplayedReports++; |
81
|
|
|
|
82
|
|
|
if ($numberDiplayedReports === $limit || $numberDiplayedReports === $nbReports) { |
83
|
|
|
$line = Console::text(' (', 'white'); |
84
|
|
|
$line .= Console::text($numberDiplayedReports, 'lightyellow'); |
85
|
|
|
$line .= Console::text('/', 'white'); |
86
|
|
|
$line .= Console::text($nbReports, 'lightyellow'); |
87
|
|
|
$line .= Console::text($numberDiplayedReports > 1 ? ' IPs displayed)': ' IP displayed)', 'white'); |
88
|
|
|
Console::log($line); |
89
|
|
|
break; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
} else { |
94
|
|
|
// no reports |
95
|
|
|
$day = $maxAge > 1 ? 'in last '. $maxAge . ' days': ' today'; |
96
|
|
|
Console::log( Console::text(' ✓', 'green') . Console::text(' No IP reported ' . $day)); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
} |