有一个程序,需在断网和在线的模式下反复做测试,如何实现定时断开网络和连接网络?最好根据IP和Port来实现次功能,因为可能不止一台电脑来做同步测试,谢谢!

解决方案 »

  1.   

    判断网络连接 
    [DllImport("wininet.dll")]
            private extern static bool InternetGetConnectedState(out int connectionDescription, int reservedValue);
            public bool IsInternetConnected()
            {
                int i = 0;
                return InternetGetConnectedState(out i, 0);
            }
    WebClient wb = new WebClient();
    Regex regIP = new Regex("\\d{1,3}.\\d{1,3}.\\d{1,3}.\\d{1,3}");
     try
      {
       string strContent = wb.DownloadString("http://www.ip138.com/ips8.asp");
      }
      catch
      {}