加班写程序 现在遇到个小问题,我是新手,请大虾们指教就是我要实现一个对远程终端的访问。连接之前 我要检测当前网络的 状况如果正常,连接不正常,退出有没有xian相关的代码?现在 就要要!多谢了!另:网上找了一些都不能用!希望给个能用的!不够加分!

解决方案 »

  1.   

    用c#实现ping也可以吧,去ping服务器API的例子有一个,给你粘一下吧:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Net.NetworkInformation;
    using System.Net.Sockets;
    using System.Net;
    using System.Runtime.InteropServices;
    namespace Test04
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            [DllImport("wininet.dll", EntryPoint = "InternetGetConnectedState")]
            public extern static bool InternetGetConnectedState(out int conState, int reder);
            //参数说明 constate 连接说明 ,reder保留值
            public bool IsConnectedToInternet()
            {
                int Desc=0;
                return InternetGetConnectedState(out  Desc, 0);
            }
                private void button2_Click(object sender, EventArgs e)
            {
                if (IsConnectedToInternet())
                    MessageBox.Show("已连接在网上!","提示");
                else
                    MessageBox.Show("未连接在网上!!","提示"); 
            }        private void Form1_Load(object sender, EventArgs e)
            {        }        private void button1_Click(object sender, EventArgs e)
            {
                Application.Exit();
            }
         
        }
    }
      

  2.   

    非常感谢!!!刚才试验了 一下!可用!!!麻烦给我发个ping的实现好么,如果远程那个有源代码也发一个完整的 吧发到我邮箱里面吧[email protected]收到后给您加分再次感谢!!!!