111,046
社区成员
发帖
与我相关
我的任务
分享
public string sPing(string IP)
{
Ping pingSender = new Ping();
PingOptions options = new PingOptions();
options.DontFragment = true;
string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
byte[] buffer = Encoding.ASCII.GetBytes(data);
int timeout = 1200;
//string IP = "192.168.100.1";
PingReply reply = pingSender.Send(IP, timeout, buffer, options);
if (reply.Status == IPStatus.Success)
{
//string sText;
string sPing;
sPing = "网络正常";
return sPing;
}
else
{
return "网络不通";
}
}
private void Form_Load(object sender, EventArgs e)
{
public Ping ping = new Ping();
public PingReply res;
try
{
res = ping.Send("www.google.com");
}
catch (Exception a)
{
MessageBox.Show(a.Message);
}
try
{
if (res.Status != System.Net.NetworkInformation.IPStatus.Success)
{
this.reflectionLabel1.Text = "<b>请检查网络连接是否正常</b>";
}
else
{
this.reflectionLabel1.Text = "<b>已连接</b>";
}
}
catch (Exception ae)
{
MessageBox.Show(ae.Message);
}
}