{
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 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>
原文链接:https://www.f2er.com/xml/296441.html