C# 使用Ping类

string ipAddress = GetParamValue("IpAddress", "192.168.1.2");
int? port = GetParamIntValue("Port", 300);
if (string.IsNullOrEmpty(ipAddress))
{
thrownew Exception("IpAddress配置不正确。");
}
if (!port.HasValue)
{
thrownew Exception("Port配置不正确。");
}
//Ping
Ping p =new Ping();
try
{
PingReply reply
= p.Send(ipAddress, 2000);
if (reply.Status == IPStatus.Success) return "连接成功!";
}
catch (Exception)
{
}
return"连接失败,请检查IP时候配置正确!";

  

编辑器加载中...

posted @ 2011-07-21 23:46  微米大大  阅读(1033)  评论(0编辑  收藏  举报