读取xml文件里switch节点的IP和设备信息,ping设备,异常显示在
发布时间:2020-12-16 06:13:55 所属栏目:百科 来源:网络整理
导读:private void button1_Click(object sender,EventArgs e) { treeView1.Nodes.Clear(); Ping pingSender = new Ping(); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load("ip.xml"); XmlNodeList xnList = xmlDoc.SelectNodes("//switch"); foreach (XmlN
private void button1_Click(object sender,EventArgs e)
{ treeView1.Nodes.Clear(); Ping pingSender = new Ping(); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load("ip.xml"); XmlNodeList xnList = xmlDoc.SelectNodes("//switch"); foreach (XmlNode xn in xnList) { string switch_ip = (xn.SelectSingleNode("ip")).InnerText; string switch_info = xn.SelectSingleNode("info").InnerText; PingReply reply = pingSender.Send(switch_ip,120);//第一个参数为ip地址,第二个参数为ping的时间 if (reply.Status != IPStatus.Success) { treeView1.Nodes.Add(switch_ip + " ( " + switch_info + ")"); } } }
xml文件内容形如: <?xml version="1.0" encoding="GB2312" standalone="yes" ?> </company> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |