zoukankan      html  css  js  c++  java
  • ASP.NET调用dos命令获取交换机流量

      protected void btn_Cisco_Click(object sender, EventArgs e)

      {

      try

      {

      string ip = txt_ip.Value;

      string community = txt_ttm.Value;

      string oid = txt_oid.Value;

      string outoid = txt_outoid.Value;

      string city = txt_city.Value;

      //执行进出口流量的dos命令

      string cmd = Dos + " " + community + " " + ip + " " + oid + "&&" + Dos + " " + community + " " + ip + " " + outoid;

      string ExecuteDos = GetExecuteDos.ExecuteDos(cmd, 180000);

      string OutValue = string.Empty;

      string InValue = string.Empty;

      if (!string.IsNullOrEmpty(ExecuteDos))

      {

      ExecuteDos = ExecuteDos.Replace("SNMPv2 - SMI", "$");

      string[] strs = ExecuteDos.Split('$');

      foreach (var item in strs)

      {

      OutValue = item.Substring(item.LastIndexOf("INTEGER:") + 8);

      }

      foreach (var item in strs)

      {

      InValue = item.Substring(item.IndexOf("INTEGER:") + 8);

      InValue = InValue.Replace("SNMPv2-SMI::enterprises.9.2.2.1.1.8.10201 = INTEGER:", "");

      string arry = InValue.Replace(" ", "&");

      string[] value = arry.Split('&');

      for (int i = 0; i < value.Length - 1; i++)

      {

      if (i == 0)

      {

      InValue = value[0];

      break;

      }

      }

      }

      Model.Host model = new Host();

      model.hostname = ip;

      model.oid = oid;

      model.Outoid = outoid;

      model.community = community;

      model.city = city;

      model.addtime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

      model.OutOctets = (float)Math.Round(Convert.ToSingle(OutValue) / 1024 / 1024, 2);

      model.InOctets = (float)Math.Round(Convert.ToSingle(InValue) / 1024 / 1024, 2);

      int res = bll.addHostIp(model);

      if(res > 0)

      {

      Response.Write("进口流量为:" + Math.Round(Convert.ToSingle(InValue) / 1024 / 1024, 2)+ ""+"MB" +"出口流量为:" + Math.Round(Convert.ToSingle(OutValue) / 1024 / 1024, 2)+ ""+"MB");

      }

      }

      }

      catch (Exception ex)

      {

      Response.Write("");

      }

      }

      }

      (编辑:雷林鹏 来源:网络)

  • 相关阅读:
    Python+selenium常见报错
    jmeter压力测试指标解释
    jemte自动生成测试报告方法
    iview清空Date-picker组件后请求报错解决方法
    【求助】Django+vue项目时候遇到一个问题,table的data数据怎么更新
    django_数据库操作—增、删、改、查
    django-关于manage.py migrate无效的问题
    python家里的环境和公司环境怎么同步
    python class类的属性应用及init初始化实践 ---勇者斗恶龙
    IDLE与pycharm执行相同代码结果却不同,原因分析
  • 原文地址:https://www.cnblogs.com/pengpeng1208/p/9292940.html
Copyright © 2011-2022 走看看