您的位置:首页 > 编程语言 > C#

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;

}

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: