Skip to content

Commit

Permalink
Function get_wireless_interface_name() added. Issue #32.
Browse files Browse the repository at this point in the history
  • Loading branch information
martignoni committed Jul 13, 2018
1 parent ae25d6e commit 5e8f8fb
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions classes/local/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,23 @@ public static function parse_config_file($file, $mode = false, $scannermode = IN
return parse_ini_string(preg_replace('/^#.*\\n/m', '', @file_get_contents($file)), $mode, $scannermode);
}

/**
* Get wireless interface name. Usually 'wlan0'.
*
* @return string containing interface name
*/
public static function get_wireless_interface_name() {
$path = realpath('/sys/class/net');

$iter = new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS +
\RecursiveDirectoryIterator::FOLLOW_SYMLINKS);
$iter = new \RecursiveIteratorIterator($iter, \RecursiveIteratorIterator::CHILD_FIRST);
$iter = new \RegexIterator($iter, '|^.*/wireless$|i', \RecursiveRegexIterator::GET_MATCH);
$iter->setMaxDepth(2);

$interface = explode('/', array_keys(iterator_to_array($iter))[0])[4];

return $interface;
}

}

0 comments on commit 5e8f8fb

Please sign in to comment.