您的位置:首页 > 理论基础 > 计算机网络

检测网络是否连接正常

2011-11-02 15:48 267 查看
在项目中用到了网络检测,有两种方法可以用。、
1、ping方法
Ping ping = new Ping();     PingReply reply = ping.Send(可以访问的网址,超时毫秒数);    if (reply.Status == IPStatus.Success)        连接正常;
2、调用系统dll
[DllImport("winInet.dll")]    private static extern bool InternetGetConnectedState(ref int nFlags, int nReserved);    public static bool CheckInternet()    {         int nFlags = 0;        return InternetGetConnectedState(ref nFlags, 0);    }
本文出自 “西北白杨树” 博客,请务必保留此出处http://yangyoushan.blog.51cto.com/7229571/1276906
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: