Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. SystemNodeProvider.php

function SystemNodeProvider::getSysfs

Returns MAC address from the first system interface via the sysfs interface

1 call to SystemNodeProvider::getSysfs()
SystemNodeProvider::getNodeFromSystem in vendor/ramsey/uuid/src/Provider/Node/SystemNodeProvider.php
Returns the system node, if it can find it

File

vendor/ramsey/uuid/src/Provider/Node/SystemNodeProvider.php, line 150

Class

SystemNodeProvider
SystemNodeProvider retrieves the system node ID, if possible

Namespace

Ramsey\Uuid\Provider\Node

Code

protected function getSysfs() : string {
    $mac = '';
    
    /**
     * @psalm-suppress UnnecessaryVarAnnotation
     * @var string $phpOs
     */
    $phpOs = constant('PHP_OS');
    if (strtoupper($phpOs) === 'LINUX') {
        $addressPaths = glob('/sys/class/net/*/address', GLOB_NOSORT);
        if ($addressPaths === false || count($addressPaths) === 0) {
            return '';
        }
        
        /** @var array<array-key, string> $macs */
        $macs = [];
        array_walk($addressPaths, function (string $addressPath) use (&$macs) : void {
            if (is_readable($addressPath)) {
                $macs[] = file_get_contents($addressPath);
            }
        });
        
        /** @var callable $trim */
        $trim = 'trim';
        $macs = array_map($trim, $macs);
        // Remove invalid entries.
        $macs = array_filter($macs, function (string $address) {
            return $address !== '00:00:00:00:00:00' && preg_match(self::SYSFS_PATTERN, $address);
        });
        
        /** @var string|bool $mac */
        $mac = reset($macs);
    }
    return (string) $mac;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal