当前位置: 首页>>代码示例>>PHP>>正文


PHP NetDevice::getName方法代码示例

本文整理汇总了PHP中NetDevice::getName方法的典型用法代码示例。如果您正苦于以下问题:PHP NetDevice::getName方法的具体用法?PHP NetDevice::getName怎么用?PHP NetDevice::getName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NetDevice的用法示例。


在下文中一共展示了NetDevice::getName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _network

 /**
  * Network devices
  * includes also rx/tx bytes
  *
  * @return void
  */
 protected function _network()
 {
     if (CommonFunctions::rfts('/proc/net/dev', $bufr, 0, 4096, PSI_DEBUG)) {
         $bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
         foreach ($bufe as $buf) {
             if (preg_match('/:/', $buf)) {
                 list($dev_name, $stats_list) = preg_split('/:/', $buf, 2);
                 $stats = preg_split('/\\s+/', trim($stats_list));
                 $dev = new NetDevice();
                 $dev->setName(trim($dev_name));
                 $dev->setRxBytes($stats[0]);
                 $dev->setTxBytes($stats[8]);
                 $dev->setErrors($stats[2] + $stats[10]);
                 $dev->setDrops($stats[3] + $stats[11]);
                 if (defined('PSI_SHOW_NETWORK_INFOS') && PSI_SHOW_NETWORK_INFOS) {
                     if (CommonFunctions::executeProgram('ifconfig', trim($dev_name) . ' 2>/dev/null', $bufr2, PSI_DEBUG)) {
                         $bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
                         foreach ($bufe2 as $buf2) {
                             //                                if (preg_match('/^'.trim($dev_name).'\s+Link\sencap:Ethernet\s+HWaddr\s(\S+)/i', $buf2, $ar_buf2)
                             if (preg_match('/\\s+encap:Ethernet\\s+HWaddr\\s(\\S+)/i', $buf2, $ar_buf2) || preg_match('/^\\s+ether\\s+(\\S+)\\s+txqueuelen/i', $buf2, $ar_buf2)) {
                                 $dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . preg_replace('/:/', '-', strtoupper($ar_buf2[1])));
                             } elseif (preg_match('/^\\s+inet\\saddr:(\\S+)\\s+P-t-P:(\\S+)/i', $buf2, $ar_buf2) || preg_match('/^\\s+inet\\s+(\\S+)\\s+netmask.+destination\\s+(\\S+)/i', $buf2, $ar_buf2)) {
                                 if ($ar_buf2[1] != $ar_buf2[2]) {
                                     $dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . $ar_buf2[1] . ";:" . $ar_buf2[2]);
                                 } else {
                                     $dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . $ar_buf2[1]);
                                 }
                             } elseif (preg_match('/^\\s+inet\\saddr:(\\S+)/i', $buf2, $ar_buf2) || preg_match('/^\\s+inet\\s+(\\S+)\\s+netmask/i', $buf2, $ar_buf2) || preg_match('/^' . trim($dev_name) . ':\\s+ip\\s+(\\S+)\\s+mask/i', $buf2, $ar_buf2) || preg_match('/^\\s+inet6\\saddr:\\s([^\\/]+)(.+)\\s+Scope:[GH]/i', $buf2, $ar_buf2) || preg_match('/^\\s+inet6\\s+(\\S+)\\s+prefixlen(.+)((<global>)|(<host>))/i', $buf2, $ar_buf2)) {
                                 $dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . strtolower($ar_buf2[1]));
                             }
                         }
                     }
                     if (CommonFunctions::rfts('/sys/class/net/' . trim($dev_name) . '/speed', $buf, 1, 4096, false) && trim($buf) != "" && $buf > 0 && $buf < 65535) {
                         $speed = trim($buf);
                         if ($speed > 1000) {
                             $speed = $speed / 1000;
                             $unit = "G";
                         } else {
                             $unit = "M";
                         }
                         if (CommonFunctions::rfts('/sys/class/net/' . trim($dev_name) . '/duplex', $buf, 1, 4096, false) && trim($buf) != "") {
                             $dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . $speed . $unit . 'b/s ' . strtolower(trim($buf)));
                         } else {
                             $dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . $speed . $unit . 'b/s');
                         }
                     }
                 }
                 $this->sys->setNetDevices($dev);
             }
         }
     } elseif (CommonFunctions::executeProgram('ifconfig', '-a', $bufr, PSI_DEBUG)) {
         $lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
         $was = false;
         foreach ($lines as $line) {
             if (preg_match("/^([^\\s:]+)/", $line, $ar_buf)) {
                 if ($was) {
                     $dev->setErrors($errors);
                     $dev->setDrops($drops);
                     if ($speedinfo != "") {
                         $dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . $speedinfo);
                     }
                     $this->sys->setNetDevices($dev);
                 }
                 $errors = 0;
                 $drops = 0;
                 $speedinfo = "";
                 $dev = new NetDevice();
                 $dev->setName($ar_buf[1]);
                 $was = true;
                 if (defined('PSI_SHOW_NETWORK_INFOS') && PSI_SHOW_NETWORK_INFOS) {
                     if (CommonFunctions::rfts('/sys/class/net/' . $dev->getName() . '/speed', $buf, 1, 4096, false) && trim($buf) != "") {
                         $speed = trim($buf);
                         if ($speed > 1000) {
                             $speed = $speed / 1000;
                             $unit = "G";
                         } else {
                             $unit = "M";
                         }
                         if (CommonFunctions::rfts('/sys/class/net/' . $dev->getName() . '/duplex', $buf, 1, 4096, false) && trim($buf) != "") {
                             $speedinfo = $speed . $unit . 'b/s ' . strtolower(trim($buf));
                         } else {
                             $speedinfo = $speed . $unit . 'b/s';
                         }
                     }
                     if (preg_match('/^' . $ar_buf[1] . '\\s+Link\\sencap:Ethernet\\s+HWaddr\\s(\\S+)/i', $line, $ar_buf2)) {
                         $dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . preg_replace('/:/', '-', strtoupper($ar_buf2[1])));
                     } elseif (preg_match('/^' . $ar_buf[1] . ':\\s+ip\\s+(\\S+)\\s+mask/i', $line, $ar_buf2)) {
                         $dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . $ar_buf2[1]);
                     }
                 }
             } else {
                 if ($was) {
                     if (preg_match('/\\sRX bytes:(\\d+)\\s/i', $line, $ar_buf2)) {
                         $dev->setRxBytes($ar_buf2[1]);
//.........这里部分代码省略.........
开发者ID:arris69,项目名称:phpsysinfo,代码行数:101,代码来源:class.Linux.inc.php

示例2: _network

 /**
  * Network devices
  *
  * @return void
  */
 private function _network()
 {
     $allDevices = CommonFunctions::getWMI($this->_wmi, 'Win32_PerfRawData_Tcpip_NetworkInterface', array('Name', 'BytesSentPersec', 'BytesTotalPersec', 'BytesReceivedPersec', 'PacketsReceivedErrors', 'PacketsReceivedDiscarded', 'CurrentBandwidth'));
     $allNetworkAdapterConfigurations = CommonFunctions::getWMI($this->_wmi, 'Win32_NetworkAdapterConfiguration', array('Description', 'MACAddress', 'IPAddress', 'SettingID'));
     $allNetworkAdapter = CommonFunctions::getWMI($this->_wmi, 'Win32_NetworkAdapter', array('Name', 'GUID', 'Speed'));
     foreach ($allDevices as $device) {
         $dev = new NetDevice();
         $name = $device['Name'];
         if (preg_match('/^isatap\\.({[A-Fa-f0-9\\-]*})/', $name, $ar_name)) {
             //isatap device
             foreach ($allNetworkAdapterConfigurations as $NetworkAdapterConfiguration) {
                 if ($ar_name[1] == $NetworkAdapterConfiguration['SettingID']) {
                     $dev->setName($NetworkAdapterConfiguration['Description']);
                     if (defined('PSI_SHOW_NETWORK_INFOS') && PSI_SHOW_NETWORK_INFOS) {
                         $dev->setInfo(preg_replace('/:/', '-', strtoupper($NetworkAdapterConfiguration['MACAddress'])));
                         if (isset($NetworkAdapterConfiguration['IPAddress'])) {
                             foreach ($NetworkAdapterConfiguration['IPAddress'] as $ipaddres) {
                                 if ($ipaddres != "0.0.0.0" && $ipaddres != "::" && !preg_match('/^fe80::/i', $ipaddres)) {
                                     $dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . strtolower($ipaddres));
                                 }
                             }
                         }
                     }
                     break;
                 }
             }
             if (defined('PSI_SHOW_NETWORK_INFOS') && PSI_SHOW_NETWORK_INFOS) {
                 $speedinfo = null;
                 foreach ($allNetworkAdapter as $NetworkAdapter) {
                     if ($ar_name[1] == $NetworkAdapter['GUID']) {
                         if (!empty($NetworkAdapter['Speed']) && $NetworkAdapter['Speed'] !== "9223372036854775807") {
                             if ($NetworkAdapter['Speed'] > 1000000000) {
                                 $speedinfo = $NetworkAdapter['Speed'] / 1000000000 . "Gb/s";
                             } else {
                                 $speedinfo = $NetworkAdapter['Speed'] / 1000000 . "Mb/s";
                             }
                         }
                         break;
                     }
                 }
                 if ($speedinfo !== null && $speedinfo !== "") {
                     $dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . $speedinfo);
                 } elseif (($speedinfo = $device['CurrentBandwidth']) >= 1000000) {
                     $dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . $speedinfo / 1000000 . "Mb/s");
                 }
             }
         }
         if ($dev->getName() == "") {
             //no isatap or no isatap description
             $cname = preg_replace('/[^A-Za-z0-9]/', '_', $name);
             //convert to canonical
             if (preg_match('/\\s-\\s([^-]*)$/', $name, $ar_name)) {
                 $name = substr($name, 0, strlen($name) - strlen($ar_name[0]));
             }
             $dev->setName($name);
             if (defined('PSI_SHOW_NETWORK_INFOS') && PSI_SHOW_NETWORK_INFOS) {
                 foreach ($allNetworkAdapterConfigurations as $NetworkAdapterConfiguration) {
                     if (preg_replace('/[^A-Za-z0-9]/', '_', $NetworkAdapterConfiguration['Description']) === $cname) {
                         if ($dev->getInfo() !== null) {
                             $dev->setInfo('');
                             //multiple with the same name
                         } else {
                             $dev->setInfo(preg_replace('/:/', '-', strtoupper($NetworkAdapterConfiguration['MACAddress'])));
                             if (isset($NetworkAdapterConfiguration['IPAddress'])) {
                                 foreach ($NetworkAdapterConfiguration['IPAddress'] as $ipaddres) {
                                     if ($ipaddres != "0.0.0.0" && !preg_match('/^fe80::/i', $ipaddres)) {
                                         $dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . strtolower($ipaddres));
                                     }
                                 }
                             }
                         }
                     }
                 }
                 $speedinfo = null;
                 foreach ($allNetworkAdapter as $NetworkAdapter) {
                     if (preg_replace('/[^A-Za-z0-9]/', '_', $NetworkAdapter['Name']) === $cname) {
                         if ($speedinfo !== null) {
                             $speedinfo = "";
                             //multiple with the same name
                         } else {
                             if (!empty($NetworkAdapter['Speed']) && $NetworkAdapter['Speed'] !== "9223372036854775807") {
                                 if ($NetworkAdapter['Speed'] > 1000000000) {
                                     $speedinfo = $NetworkAdapter['Speed'] / 1000000000 . "Gb/s";
                                 } else {
                                     $speedinfo = $NetworkAdapter['Speed'] / 1000000 . "Mb/s";
                                 }
                             } else {
                                 $speedinfo = "";
                             }
                         }
                     }
                 }
                 if ($speedinfo !== null && $speedinfo !== "") {
                     $dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . $speedinfo);
                 } elseif (($speedinfo = $device['CurrentBandwidth']) >= 1000000) {
//.........这里部分代码省略.........
开发者ID:zseand,项目名称:phpsysinfo,代码行数:101,代码来源:class.WINNT.inc.php


注:本文中的NetDevice::getName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。