From 5e8f8fbb136f3edcedbed91ec8f8d927d45c8cb5 Mon Sep 17 00:00:00 2001 From: Nicolas Martignoni Date: Fri, 13 Jul 2018 14:12:27 +0200 Subject: [PATCH] Function get_wireless_interface_name() added. Issue #32. --- classes/local/utils.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/classes/local/utils.php b/classes/local/utils.php index bbab7f1..16424fa 100644 --- a/classes/local/utils.php +++ b/classes/local/utils.php @@ -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; + } + }