请问:C#中有没有测试网络是否通畅的简单语句?

foxqd 2017-08-24 09:58:26
如题。比如上传服务器的网址为10.14.25.135,在本地如何用简单的语句来即时判断本机至10.14.25.135这个网址目前是否连通还是网路不通?谢谢!
...全文
268 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
homesos 2017-08-24
  • 打赏
  • 举报
回复

[System.Runtime.InteropServices.DllImport("winInet.dll")]
private extern static bool InternetCheckConnection(String url, int flag, int ReservedValue);

if (InternetCheckConnection("http://www.baidu.com", 1, 0))
 {
                    //联网
}
易2017 2017-08-24
  • 打赏
  • 举报
回复
 #region 网络状况判断
        [DllImport("winInet.dll ")]    //判断联网状态
        private static extern bool InternetGetConnectedState(ref int Description, int ReservedValue);
        static int Description;//返回值,指示网络状态
        #endregion
ilikeff8 2017-08-24
  • 打赏
  • 举报
回复
            using System.Net.NetworkInformation;

            bool isOk = new Ping().Send("192.16.1.1", 100).Status == IPStatus.Success;
  • 打赏
  • 举报
回复
联通了,就是联通;否则超时之后就是不联通。
白衣如花 2017-08-24
  • 打赏
  • 举报
回复

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧