日期:2014-05-17 浏览次数:20884 次
private const int INTERNET_CONNECTION_MODEM = 1;
private const int INTERNET_CONNECTION_LAN = 2;
[DllImport("winInet.dll")]
private static extern bool InternetGetConnectedState(
ref int dwFlag,
int dwReserved
);
//调用的方法(Winform为例,放一个按钮,单击即可):
private void button1_Click(object sender, System.EventArgs e){
System.Int32 dwFlag = new int();
if(!InternetGetConnectedState(ref dwFlag, 0))
MessageBox.Show("未连网!");
else
if((dwFlag & INTERNET_CONNECTION_MODEM)!=0)
MessageBox.Show("采用调治解调器上网。");
else
if((dwFlag & INTERNET_CONNECTION_LAN)!=0)
MessageBox.Show("采用网卡上网。");
}
public sealed class NetworkHelper
{
#region 网络状态
/// <summary>
/// 监听计时器
/// </summary>
private Timer listenTimer;
private static NetworkHelper instance;
/// <summary>
/// 监听间隔
/// </summary>
const int LISTEN_TIME_SPAN = 2000;
//IsNetworkAlive Description