php snmpwalk array_chunk() 函数一次读取SNMP table数据并解析的简便方法

array_chunk() 函数

 

--------------------- 

 hrSWRunTable    1.3.6.1.2.1.25.4.2
 hrSWRunEntry    1.3.6.1.2.1.25.4.2.1
 hrSWRunIndex    1.3.6.1.2.1.25.4.2.1.1
 hrSWRunName    1.3.6.1.2.1.25.4.2.1.2
 hrSWRunID    1.3.6.1.2.1.25.4.2.1.3
 hrSWRunPath    1.3.6.1.2.1.25.4.2.1.4
 hrSWRunParameters    1.3.6.1.2.1.25.4.2.1.5
 hrSWRunType    1.3.6.1.2.1.25.4.2.1.6
 hrSWRunStatus    1.3.6.1.2.1.25.4.2.1.7
--------------------- 

        public function process(){
        $process = array();
        $result = snmpwalk($this->ip, $this->community, '1.3.6.1.2.1.25.4.2.1');
        $process = array_chunk($result,count($result)/7);
        return $process;
    }

--------------------- 

 tcpConnTable    1.3.6.1.2.1.6.13
 tcpConnEntry    1.3.6.1.2.1.6.13.1
 tcpConnState    1.3.6.1.2.1.6.13.1.1
 tcpConnLocalAddress    1.3.6.1.2.1.6.13.1.2
 tcpConnLocalPort    1.3.6.1.2.1.6.13.1.3
 tcpConnRemAddress    1.3.6.1.2.1.6.13.1.4
 tcpConnRemPort    1.3.6.1.2.1.6.13.1.5
--------------------- 
 

        public function tcp(){
        $tcp = array();
        $result = snmpwalk($this->ip, $this->community, '1.3.6.1.2.1.6.13.1');
        $tcp = array_chunk($result,count($result)/5);
        return $tcp;
    }
 

 

运行结果示例:


array(5) {
  [0]=>
  array(11) {
    [0]=>
    string(18) "INTEGER: listen(2)"
    [1]=>
    string(18) "INTEGER: listen(2)"
    [2]=>
    string(18) "INTEGER: listen(2)"
    [3]=>
    string(18) "INTEGER: listen(2)"
    [4]=>
    string(18) "INTEGER: listen(2)"
    [5]=>
    string(18) "INTEGER: listen(2)"
    [6]=>
    string(18) "INTEGER: listen(2)"
    [7]=>
    string(23) "INTEGER: established(5)"
    [8]=>
    string(23) "INTEGER: established(5)"
    [9]=>
    string(23) "INTEGER: synReceived(4)"
    [10]=>
    string(18) "INTEGER: listen(2)"
  }
  [1]=>
  array(11) {
    [0]=>
    string(18) "IpAddress: 0.0.0.0"
    [1]=>
    string(18) "IpAddress: 0.0.0.0"
    [2]=>
    string(18) "IpAddress: 0.0.0.0"
    [3]=>
    string(18) "IpAddress: 0.0.0.0"
    [4]=>
    string(20) "IpAddress: 127.0.0.1"
    [5]=>
    string(20) "IpAddress: 127.0.0.1"
    [6]=>
    string(20) "IpAddress: 127.0.0.1"
    [7]=>
    string(26) "IpAddress: 192.168.111.139"
    [8]=>
    string(26) "IpAddress: 192.168.111.139"
    [9]=>
    string(26) "IpAddress: 192.168.111.139"
    [10]=>
    string(24) "IpAddress: 192.168.122.1"
  }
  [2]=>
  array(11) {
    [0]=>
    string(11) "INTEGER: 22"
    [1]=>
    string(12) "INTEGER: 111"
    [2]=>
    string(13) "INTEGER: 3306"
    [3]=>
    string(13) "INTEGER: 6000"
    [4]=>
    string(11) "INTEGER: 25"
    [5]=>
    string(12) "INTEGER: 199"
    [6]=>
    string(12) "INTEGER: 631"
    [7]=>
    string(11) "INTEGER: 22"
    [8]=>
    string(11) "INTEGER: 22"
    [9]=>
    string(11) "INTEGER: 80"
    [10]=>
    string(11) "INTEGER: 53"
  }
  [3]=>
  array(11) {
    [0]=>
    string(18) "IpAddress: 0.0.0.0"
    [1]=>
    string(18) "IpAddress: 0.0.0.0"
    [2]=>
    string(18) "IpAddress: 0.0.0.0"
    [3]=>
    string(18) "IpAddress: 0.0.0.0"
    [4]=>
    string(18) "IpAddress: 0.0.0.0"
    [5]=>
    string(18) "IpAddress: 0.0.0.0"
    [6]=>
    string(18) "IpAddress: 0.0.0.0"
    [7]=>
    string(24) "IpAddress: 192.168.111.1"
    [8]=>
    string(24) "IpAddress: 192.168.111.1"
    [9]=>
    string(24) "IpAddress: 192.168.111.1"
    [10]=>
    string(18) "IpAddress: 0.0.0.0"
  }
  [4]=>
  array(11) {
    [0]=>
    string(10) "INTEGER: 0"
    [1]=>
    string(10) "INTEGER: 0"
    [2]=>
    string(10) "INTEGER: 0"
    [3]=>
    string(10) "INTEGER: 0"
    [4]=>
    string(10) "INTEGER: 0"
    [5]=>
    string(10) "INTEGER: 0"
    [6]=>
    string(10) "INTEGER: 0"
    [7]=>
    string(14) "INTEGER: 49711"
    [8]=>
    string(14) "INTEGER: 50128"
    [9]=>
    string(14) "INTEGER: 50248"
    [10]=>
    string(10) "INTEGER: 0"
  }
}
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值