62 lines
1.6 KiB
PHP
62 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Domovoy\Services\Discovery;
|
|
|
|
class HostFingerprintService
|
|
{
|
|
/**
|
|
* Guess vendor based on open ports and hostname.
|
|
*/
|
|
public function guessVendor(array $openPorts, ?string $hostname): ?string
|
|
{
|
|
$portVendorMap = [
|
|
9100 => 'HP/Printer',
|
|
631 => 'CUPS/Apple',
|
|
548 => 'Apple/AFP',
|
|
445 => 'Microsoft/SMB',
|
|
22 => null, // Too common
|
|
];
|
|
|
|
foreach ($portVendorMap as $port => $vendor) {
|
|
if ($vendor !== null && in_array($port, $openPorts, true)) {
|
|
return $vendor;
|
|
}
|
|
}
|
|
|
|
if ($hostname !== null) {
|
|
$hostname = strtolower($hostname);
|
|
if (str_contains($hostname, 'apple') || str_contains($hostname, 'macbook') || str_contains($hostname, 'iphone')) {
|
|
return 'Apple';
|
|
}
|
|
if (str_contains($hostname, 'synology') || str_contains($hostname, 'nas')) {
|
|
return 'Synology';
|
|
}
|
|
if (str_contains($hostname, 'router') || str_contains($hostname, 'gateway')) {
|
|
return 'Router/Network';
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Calculate confidence score 0-100 based on found data.
|
|
*/
|
|
public function calculateConfidence(int $openPortCount, bool $hasHostname): int
|
|
{
|
|
$score = 10; // Base: host is alive
|
|
|
|
if ($openPortCount > 0) {
|
|
$score += min(40, $openPortCount * 5);
|
|
}
|
|
|
|
if ($hasHostname) {
|
|
$score += 30;
|
|
}
|
|
|
|
return min(100, $score);
|
|
}
|
|
}
|