当前位置: 移动技术网 > IT编程>开发语言>.net > ASP.NET调用dos命令获取交换机流量

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

2018年04月18日  | 移动技术网IT编程  | 我要评论

刘瑞琪老公,扣子妹,9080影院

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>");
}
}
}

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网