123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- declare(strict_types=1);
- namespace OC\Net;
- use function filter_var;
- use function in_array;
- use function strrchr;
- use function substr;
- use function substr_count;
- class HostnameClassifier {
- private const LOCAL_TOPLEVEL_DOMAINS = [
- 'local',
- 'localhost',
- 'intranet',
- 'internal',
- 'private',
- 'corp',
- 'home',
- 'lan',
- ];
-
- public function isLocalHostname(string $hostname): bool {
-
- $topLevelDomain = substr((strrchr($hostname, '.') ?: ''), 1);
- if (in_array($topLevelDomain, self::LOCAL_TOPLEVEL_DOMAINS)) {
- return true;
- }
-
- if (substr_count($hostname, '.') === 0 && !filter_var($hostname, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
- return true;
- }
- return false;
- }
- }
|