码迷,mamicode.com
首页 > Web开发 > 详细

ASP.NET调用dos命令获取交换机流量

时间:2018-04-17 19:43:10      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:nmp   add   mod   comm   substr   type   catch   script   nta   

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("\r\n", "&");
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("<script type=‘text/javascript‘>alert(‘" + ex.Message + "‘)</script>");
}
}
}

ASP.NET调用dos命令获取交换机流量

标签:nmp   add   mod   comm   substr   type   catch   script   nta   

原文地址:https://www.cnblogs.com/chengxing124/p/8868475.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!