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