C#检测是否联网
2016-03-07 11:58
417 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace LocalApp.ConsoleApp.Core
{
public class Net
{
[DllImport("wininet")]
private extern static bool InternetGetConnectedState(out int connectionDescription, int reservedValue);
/**//// <summary>
/// 检测本机是否联网
/// </summary>
/// <returns></returns>
public static bool IsConnectedInternet()
{
int i = 0;
if (InternetGetConnectedState(out i, 0))
{
//已联网
return true;
}
else
{
//未联网
return false;
}
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace LocalApp.ConsoleApp.Core
{
public class Net
{
[DllImport("wininet")]
private extern static bool InternetGetConnectedState(out int connectionDescription, int reservedValue);
/**//// <summary>
/// 检测本机是否联网
/// </summary>
/// <returns></returns>
public static bool IsConnectedInternet()
{
int i = 0;
if (InternetGetConnectedState(out i, 0))
{
//已联网
return true;
}
else
{
//未联网
return false;
}
}
}
}
相关文章推荐
- C#读取Windows日志
- 【开源】.Net 分布式服务中心
- 安装服务时遇到 System.BadImageFormatException: 未能加载文件或程序集
- 从0自学C#08--绘制曲线chart控件
- 在C#的类库中添加web service引用
- C#第四节课
- C#多态的实现:虚方法、抽象类、接口
- C#文件路径的写法
- C# 收发和处理自定义的WINDOWS消息
- C#使用SOAP调用Web Service
- C# 4 中使用迭代器的等待任务
- C#控制定位Word光标移动到任意行或者最后一行,取得光标位置等操作
- about data type in c#
- c#操作word表格
- 背水一战 Windows 10 (1) - C# 6.0 新特性
- c#虚方法和抽象方法的区别
- c# GroupBox 只修改标题的字体和颜色
- C#基础
- C#语言基础—运算符
- C#语言基础— 数据类型及其转换