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

2018-06-22 07:57:47来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

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

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:【ASP.NET MVC系列】浅谈ASP.NET MVC八大类扩展(上篇)

下一篇:WebApi-路由机制