function getInterfaces() { $output = NetworkBo::sendCommand("ifconfig"); $lines = preg_split("/\n/", $output); $currentInterface = array(); $interfaces = array(); foreach ($lines as $index => $line) { if (!$line) { if (isset($currentInterface["name"])) { $interfaces[$currentInterface["name"]] = $currentInterface; } $currentInterface = array(); } else { // echo $line . "<br>"; // print_r($currentInterface); // echo "<br>"; $re = "/^([a-z0-9\\.\\-]+)\\s*Link encap:([A-Za-z0-9]+)\\s*(HWaddr)?\\s*([a-z0-9:\\-]*)/"; preg_match_all($re, $line, $matches); if ($matches[0]) { $currentInterface["name"] = $matches[1][0]; if ($matches[4]) { $currentInterface["mac"] = $matches[4][0]; } } $re = "/addr:([0-9\\.]*)/"; preg_match_all($re, $line, $matches); if ($matches[1] && $matches[1][0]) { $currentInterface["ip_v4"] = $matches[1][0]; } $re = "/6 addr:\\s*([a-z0-9\\:\\/\\-%]*) Scope:(\\w*)/"; preg_match_all($re, $line, $matches); if ($matches[1] && $matches[1][0]) { // print_r($matches); // echo "<br>"; $currentInterface["ip_v6_" . strtolower($matches[2][0])] = $matches[1][0]; } } } // print_r($interfaces); // echo "<br>"; return $interfaces; }
<?php /* Copyright 2014-2015 Cédric Levieux, Jérémy Collot, ArmagNet This file is part of Parpaing. Parpaing is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Parpaing is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Parpaing. If not, see <http://www.gnu.org/licenses/>. */ session_start(); require_once "config/config.php"; require_once "engine/utils/SessionUtils.php"; require_once 'engine/bo/NetworkBo.' . $config["parpaing"]["dialect"] . '.php'; if (!SessionUtils::isConnected($_SESSION)) { exit; } $networkBo = NetworkBo::newInstance($config); $ip = $_REQUEST["ip"]; $ips = $networkBo->scan($ip); echo json_encode(array("ok" => "ok", "ips" => $ips));
function getInterfaces() { $output = NetworkBo::sendCommand("ifconfig"); $lines = preg_split("/\n/", $output); $currentInterface = array(); $interfaces = array(); foreach ($lines as $index => $line) { if (!$line) { if (isset($currentInterface["name"])) { $interfaces[$currentInterface["name"]] = $currentInterface; } $currentInterface = array(); } else { $re = "/^([a-z0-9\\.]+)\\s*Link encap:([A-Za-z0-9]+)\\s*(HWaddr)?\\s*([a-z0-9:\\-]*)/"; preg_match_all($re, $line, $matches); if ($matches[0]) { $currentInterface["name"] = $matches[1][0]; if ($matches[4]) { $currentInterface["mac"] = $matches[4][0]; } } $re = "/inet addr:([0-9\\.]*)/"; preg_match_all($re, $line, $matches); if ($matches[1]) { $currentInterface["ip_v4"] = $matches[1][0]; } $re = "/addr: ([a-f0-9\\:\\/]*)/"; preg_match_all($re, $line, $matches); if ($matches[1]) { $currentInterface["ip_v6"] = $matches[1][0]; } } } return $interfaces; }