using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Runtime.InteropServices;
|
using System.Text;
|
|
namespace IStation.Untity
|
{
|
/// <summary>
|
/// 网络工具类
|
/// </summary>
|
public class InternetHelper
|
{
|
private const int INTERNET_CONNECTION_MODEM = 1;
|
private const int INTERNET_CONNECTION_LAN = 2;
|
private const int INTERNET_CONNECTION_PROXY = 4;
|
private const int INTERNET_CONNECTION_MODEM_BUSY = 8;
|
|
///导入判断网络是否连接的 .dll
|
[DllImport("wininet.dll", EntryPoint = "InternetGetConnectedState")]
|
|
|
/// <summary>
|
/// 判断网络状况的方法,返回值true为连接,false为未连接
|
/// </summary>
|
/// <param name="conState"> </param>
|
/// <param name="reder"> </param>
|
public extern static bool InternetGetConnectedState(out int conState, int reder);
|
|
/*使用方法
|
var internetCode = 0;
|
var hasInternet = InternetUtils.InternetGetConnectedState(out internetCode, 0);
|
if (!hasInternet)
|
{
|
XtraMessageBox.Show("当前未连接网络!");
|
return;
|
}
|
*/
|
|
//int dwFlag = 0;
|
//string netstatus = "";
|
//if (!InternetGetConnectedState(ref dwFlag, 0))
|
//Console.WriteLine("未联网!");
|
//else
|
//{
|
//if ((dwFlag & INTERNET_CONNECTION_MODEM) != 0)
|
//netstatus += " 采用调治解调器上网 /n";
|
//if ((dwFlag & INTERNET_CONNECTION_LAN) != 0)
|
//netstatus += " 采用网卡上网 /n";
|
//if ((dwFlag & INTERNET_CONNECTION_PROXY) != 0)
|
//netstatus += " 采用代理上网 /n";
|
//if ((dwFlag & INTERNET_CONNECTION_MODEM_BUSY) != 0)
|
//netstatus += " MODEM被其他非INTERNET连接占用 /n";
|
//}
|
|
|
|
}
|
}
|