-
-
Save j0inty/2a355fb6dd143ab4d0d8 to your computer and use it in GitHub Desktop.
* added the php tag to activate the syntax highlight
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Get the all interface mac addresses. | |
* | |
* @return array|integer Return the MAC adresses as an array OR if the exec() call failed the return will be the error code from "ipconfig /all". | |
*/ | |
function get_ethernet_addresses() | |
{ | |
$physicalAddresses = array(); | |
$ipconfig_output = array(); | |
$return = 0; | |
exec('ipconfig /all', $ipconfig_output, $return); | |
if( $return == 0 ) | |
{ | |
// https://regex101.com/r/uN9dF4/3 | |
foreach( $ipconfig_output as &$line) | |
{ | |
// Empty previous values | |
$matches = array(); | |
// Let's find the MAC adresses | |
if( preg_match("/([[:blank:]][[:xdigit:]]{2}-[[:xdigit:]]{2}-[[:xdigit:]]{2}-[[:xdigit:]]{2}-[[:xdigit:]]{2}-[[:xdigit:]]{2})$/i", $line, $matches) ) | |
{ | |
$physicalAddresses[] = trim($matches[0]); | |
} | |
} | |
return $physicalAddresses; | |
} | |
return $return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment