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

c#使用winnet检测网络连接状况

2009-09-04 22:53 471 查看
注:本代码的主体内容由CSDN的xt0050提供,911仅仅对其做了整理。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace Pinyin
{
{
{
{
long lfag;
string strConnectionDev = "";
if (InternetGetConnectedState(out lfag, 0))
strConnectionDev = "网络连接正常!";
else
strConnectionDev = "网络连接不可用!";
if ((lfag & INTERNET_CONNECTION_OFFLINE) > 0)
strConnectionDev += "OFFLINE 本地系统处于离线模式。";
if ((lfag & INTERNET_CONNECTION_MODEM) > 0)
strConnectionDev += "Modem 本地系统使用调制解调器连接到互联网。";
if ((lfag & INTERNET_CONNECTION_LAN) > 0)
strConnectionDev += "LAN 本地系统使用的局域网连接到互联网。";
if ((lfag & INTERNET_CONNECTION_PROXY) > 0)
strConnectionDev += "a Proxy";
if ((lfag & INTERNET_CONNECTION_MODEM_BUSY) > 0)
strConnectionDev += "Modem but modem is busy";
MessageBox.Show(strConnectionDev);
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: