. * * @link https://www.librenms.org * * @copyright 2022 Tony Murray * @author Tony Murray */ namespace LibreNMS\Util; use ErrorException; use Illuminate\Support\Facades\Cache; use LibreNMS\Config; class AutonomousSystem { /** @var int */ private $asn; public function __construct(int $asn) { $this->asn = $asn; } /** * @param string|int $asn */ public static function get($asn): self { return new static((int) $asn); } /** * Get the ASN text from Team Cymru. * May be overridden in the config with astext. * Caches results for 1 day * * @return string */ public function name(): string { return Cache::remember("astext.$this->asn", 86400, function () { if (Config::has("astext.$this->asn")) { return Config::get("astext.$this->asn"); } try { $result = @dns_get_record("AS$this->asn.asn.cymru.com", DNS_TXT); if (! empty($result[0]['txt'])) { $txt = explode('|', $result[0]['txt']); return trim($txt[4], ' "'); } } catch (ErrorException $e) { } return ''; }); } }