mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
* Update dependencies (fix dependencies on PHP 8.2) - Removing fgrosse/phpasn1 (v2.5.0) - Removing php-cs-fixer/diff (v2.0.2) - Upgrading barryvdh/reflection-docblock (v2.0.6 => v2.1.0) - Upgrading brick/math (0.9.3 => 0.10.2) - Upgrading composer/ca-bundle (1.3.3 => 1.3.4) - Upgrading composer/composer (2.4.1 => 2.5.1) - Upgrading composer/pcre (2.0.0 => 3.1.0) - Upgrading composer/xdebug-handler (2.0.2 => 3.0.3) - Locking dflydev/dot-access-data (v3.0.2) - Upgrading doctrine/annotations (1.13.3 => 1.14.2) - Upgrading doctrine/event-manager (1.1.2 => 1.2.0) - Upgrading doctrine/inflector (2.0.5 => 2.0.6) - Upgrading dragonmantank/cron-expression (v3.3.1 => v3.3.2) - Upgrading fakerphp/faker (v1.20.0 => v1.21.0) - Upgrading filp/whoops (2.14.5 => 2.14.6) - Upgrading friendsofphp/php-cs-fixer (v3.4.0 => v3.13.1) - Upgrading guzzlehttp/psr7 (2.4.1 => 2.4.3) - Upgrading laravel-notification-channels/webpush (5.1.1 => 7.0.0) - Upgrading laravel/dusk (v6.25.1 => v6.25.2) - Upgrading laravel/framework (v8.83.23 => v8.83.27) - Upgrading laravel/serializable-closure (v1.2.1 => v1.2.2) - Upgrading laravel/socialite (v5.5.5 => v5.5.6) - Upgrading laravel/tinker (v2.7.2 => v2.7.3) - Upgrading league/commonmark (1.6.7 => 2.3.8) - Locking league/config (v1.2.0) - Upgrading league/flysystem (1.1.9 => 1.1.10) - Upgrading librenms/laravel-vue-i18n-generator (0.1.47 => 0.1.48) - Upgrading minishlink/web-push (v6.0.7 => v7.0.0) - Upgrading nesbot/carbon (2.62.1 => 2.64.0) - Locking nette/schema (v1.2.3) - Locking nette/utils (v3.2.8) - Upgrading nikic/php-parser (v4.15.1 => v4.15.2) - Upgrading nunomaduro/larastan (1.0.3 => 1.0.4) - Upgrading pear/net_dns2 (v1.5.2 => v1.5.3) - Upgrading php-amqplib/php-amqplib (v3.2.0 => v3.4.0) - Upgrading php-webdriver/webdriver (1.12.1 => 1.13.1) - Upgrading phpdocumentor/type-resolver (1.6.1 => 1.6.2) - Upgrading phpmailer/phpmailer (v6.6.4 => v6.7.1) - Upgrading phpseclib/phpseclib (3.0.16 => 3.0.18) - Upgrading phpstan/phpstan (1.8.5 => 1.8.11) - Upgrading phpunit/php-code-coverage (9.2.17 => 9.2.22) - Upgrading phpunit/phpunit (9.5.24 => 9.5.27) - Upgrading psr/cache (1.0.1 => 3.0.0) - Upgrading psr/container (1.1.1 => 1.1.2) - Upgrading psr/log (1.1.4 => 2.0.0) - Upgrading psy/psysh (v0.11.8 => v0.11.10) - Upgrading ramsey/collection (1.2.2 => 1.3.0) - Upgrading ramsey/uuid (4.2.3 => 4.7.0) - Upgrading sebastian/comparator (4.0.6 => 4.0.8) - Upgrading sebastian/exporter (4.0.4 => 4.0.5) - Upgrading sebastian/type (3.1.0 => 3.2.0) - Upgrading socialiteproviders/manager (v4.1.0 => v4.2.0) - Locking spomky-labs/pki-framework (1.0.1) - Upgrading symfony/console (v5.4.12 => v5.4.16) - Upgrading symfony/css-selector (v5.4.11 => v6.2.0) - Upgrading symfony/deprecation-contracts (v2.5.2 => v3.2.0) - Upgrading symfony/error-handler (v5.4.11 => v5.4.15) - Upgrading symfony/event-dispatcher (v5.4.9 => v6.2.2) - Upgrading symfony/event-dispatcher-contracts (v2.5.2 => v3.2.0) - Upgrading symfony/filesystem (v5.4.12 => v6.2.0) - Upgrading symfony/http-foundation (v5.4.12 => v5.4.16) - Upgrading symfony/http-kernel (v5.4.12 => v5.4.16) - Upgrading symfony/mime (v5.4.12 => v5.4.16) - Upgrading symfony/options-resolver (v5.4.11 => v6.2.0) - Upgrading symfony/polyfill-ctype (v1.26.0 => v1.27.0) - Upgrading symfony/polyfill-iconv (v1.26.0 => v1.27.0) - Upgrading symfony/polyfill-intl-grapheme (v1.26.0 => v1.27.0) - Upgrading symfony/polyfill-intl-idn (v1.26.0 => v1.27.0) - Upgrading symfony/polyfill-intl-normalizer (v1.26.0 => v1.27.0) - Upgrading symfony/polyfill-mbstring (v1.26.0 => v1.27.0) - Upgrading symfony/polyfill-php72 (v1.26.0 => v1.27.0) - Upgrading symfony/polyfill-php73 (v1.26.0 => v1.27.0) - Upgrading symfony/polyfill-php80 (v1.26.0 => v1.27.0) - Upgrading symfony/polyfill-php81 (v1.26.0 => v1.27.0) - Upgrading symfony/routing (v5.4.11 => v5.4.15) - Upgrading symfony/stopwatch (v5.4.5 => v6.2.0) - Upgrading symfony/string (v5.4.12 => v6.2.2) - Upgrading symfony/translation (v5.4.12 => v5.4.14) - Upgrading symfony/var-dumper (v5.4.11 => v5.4.14) - Upgrading tecnickcom/tcpdf (6.5.0 => 6.6.2) - Upgrading tijsverkoyen/css-to-inline-styles (2.2.4 => 2.2.5) - Upgrading vlucas/phpdotenv (v5.4.1 => v5.5.0) - Upgrading web-token/jwt-core (v2.2.11 => 3.1.4) - Upgrading web-token/jwt-key-mgmt (v2.2.11 => 3.1.4) - Upgrading web-token/jwt-signature (v2.2.11 => 3.1.4) - Upgrading web-token/jwt-signature-algorithm-ecdsa (v2.2.11 => 3.1.4) - Upgrading web-token/jwt-util-ecc (v2.2.11 => 3.1.4) * Remove Net_DNS2_Resolver workaround
89 lines
2.4 KiB
PHP
89 lines
2.4 KiB
PHP
<?php
|
|
/**
|
|
* Dns.php
|
|
*
|
|
* Get version info about LibreNMS and various components/dependencies
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*
|
|
* @link http://librenms.org
|
|
*
|
|
* @copyright 2021 Thomas Berberich
|
|
* @author Thomas Berberch <sourcehhdoctor@gmail.com>
|
|
*/
|
|
|
|
namespace LibreNMS\Util;
|
|
|
|
use App\Models\Device;
|
|
use LibreNMS\Interfaces\Geocoder;
|
|
|
|
class Dns implements Geocoder
|
|
{
|
|
protected $resolver;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->resolver = new \Net_DNS2_Resolver();
|
|
}
|
|
|
|
public static function lookupIp(Device $device): ?string
|
|
{
|
|
if (IP::isValid($device->hostname)) {
|
|
return $device->hostname;
|
|
}
|
|
|
|
try {
|
|
if ($device->transport == 'udp6' || $device->transport == 'tcp6') {
|
|
return dns_get_record($device['hostname'], DNS_AAAA)[0]['ipv6'] ?? null;
|
|
}
|
|
|
|
return dns_get_record($device['hostname'], DNS_A)[0]['ip'] ?? null;
|
|
} catch (\Exception $e) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param string $domain Domain which has to be parsed
|
|
* @param string $record DNS Record which should be searched
|
|
* @return array List of matching records
|
|
*/
|
|
public function getRecord($domain, $record = 'A')
|
|
{
|
|
try {
|
|
$ret = $this->resolver->query($domain, $record);
|
|
|
|
return $ret->answer;
|
|
} catch (\Net_DNS2_Exception $e) {
|
|
d_echo('::query() failed: ' . $e->getMessage());
|
|
|
|
return [];
|
|
}
|
|
}
|
|
|
|
public function getCoordinates($hostname)
|
|
{
|
|
$r = $this->getRecord($hostname, 'LOC');
|
|
|
|
foreach ($r as $record) {
|
|
return [
|
|
'lat' => $record->latitude ?? null,
|
|
'lng' => $record->longitude ?? null,
|
|
];
|
|
}
|
|
|
|
return [];
|
|
}
|
|
}
|