加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

读取xml文件里switch节点的IP和设备信息,ping设备,异常显示在

发布时间:2020-12-16 09:02:30 所属栏目:百科 来源:网络整理
导读: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>
<switch>
<ip>192.168.10.1</ip>
<info>H3C 5500交换机</info>
</switch>
<switch>
<ip>192.168.10.2</ip>
<info>H3C-S3100交换机</info>
</switch>

</company>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读