如何用C#编一个检测网络是否连通的工具?

来源:百度知道 编辑:UC知道 时间:2024/05/21 19:26:04
在校园网经常掉线,我想做个自动检测是否断网的工具,如果掉线 了则自动运行校园网客户端登陆上去。哪位高手指导一下
我终于知道我的编程技术烂了,给好代码也看不懂。谁能做个exe发给我bigmowu@163.com,功能主要有:每3分钟检测网络不通就关掉那个客户端进程,然后再自动运行客户端登陆上去(其中进程名用文本框读取,运行的客户端位置可以用户选取).谁做给我我把全部分给他了

ping的函数代码,已经测试成功!将此函数封装一个form或网页中,用textbox输入要ping的地址,启动一个定时器不停的判断状态,运行整个程序形成exe文件,如果需要测试,就运行以下,很简单。
public static string PingResult(string ip)
{
System.Net.NetworkInformation.Ping p = new System.Net.NetworkInformation.Ping();
System.Net.NetworkInformation.PingOptions options = new System.Net.NetworkInformation.PingOptions();
options.DontFragment = true;
string data = "aa";
byte[] buffer = Encoding.ASCII.GetBytes(data);
//Wait seconds for a reply.
int timeout = 1000 ;

System.Net.NetworkInformation.PingReply reply = p.Send(ip, timeout, buffer, options);
return reply.Status.ToString();

}

using System.Runtime.InteropServices;

[DllImport("wininet.dll")]

private extern static bool InternetGetConnectedState(out int connectionDescription, int reservedValue);

private static bool IsConnected()
{
int I = 0;<