PHP类采集SNMP hrSWInstalledTable并解析Installed_Information

<?php
    class Installed_Information
    {
        public function __construct($operating_system, $host_address)
        {
            $this->operating_system = $operating_system;
            $this->host_address     = $host_address;
            if($this->operating_system == 'windows')
            {
                $this->create_data_array();
            }
            if($this->operating_system == 'linux')
            {
                $this->create_data_array();
            }
        }
        private function create_data_array()
        {
        
        $soft = array();
        $result = snmpwalk($this->host_address, "public", '.iso.org.dod.internet.mgmt.mib-2.host.hrSWInstalled.hrSWInstalledTable.hrSWInstalledEntry');
        $soft = array_chunk($result,count($result)/5);
//            $hrSWInstalledIndex = array();
//            $hrSWInstalledIndex = snmpwalkoid($this->host_address, "public", ".iso.org.dod.internet.mgmt.mib-2.host.hrSWInstalled.hrSWInstalledTable.hrSWInstalledEntry.hrSWInstalledIndex");
            if($soft != FALSE)
            {
                if(count($soft) > 0)
                {
                    $this->data_fetched = 'yes';
                    
                    $installed_type = array();
                    $installed_name  = array();
                    $installed_date  = array();
                    for($i=0; $i<count($soft[3]); $i++)
                    {
                        $installed_type[$i] = str_replace('INTEGER: ', '', $soft[3][$i]);
                    }

                    for($i=0; $i<count($soft[1]); $i++)
                    {
                        $data = str_replace('STRING: ', '', $soft[1][$i]);
                        $data = str_replace('"', '', $data);
                        $installed_name[$i] = $data;
                    }
                    for($i=0; $i<count($soft[4]); $i++)
                    {
                        $data = str_replace('STRING: ', '', $soft[4][$i]);
                        $installed_date[$i] = $data;
                    }
                    $this->data_array[0] = $installed_type;
                    $this->data_array[1] = $installed_name;
                    $this->data_array[2] = $installed_date;
                }
                else
                {
                    $this->data_fetched = 'no';
                }
            }
            else
            {
                
            }
        }
        public function get_data_array()
        {
            return $this->data_array;
        }
        public function __destruct()
        {
            /*
             * No code needed here
             */
        }
        public $data_fetched;
        private $data_array = array();
        private $operating_system;
        private $host_address;
    }
?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值