using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace Utils.Internet
{
public class InternetUtil
{
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);
///
/// 是否联网
///
public static bool IsConnected()
{
System.Int32 dwFlag = new int();
if (!InternetGetConnectedState(ref dwFlag, 0))
return false;
return true;
}
///
/// 是否采用猫联网。如果没联网,返回false
///
public static bool IsConnectedByModem()
{
System.Int32 dwFlag = new int();
if (!InternetGetConnectedState(ref dwFlag, 0))
return false;
else if ((dwFlag & INTERNET_CONNECTION_MODEM) != 0)
return true;
return false;
}
///
/// 是否采用LAN联网。如果没联网,返回false
///
public static bool IsConnectedByLAN()
{
System.Int32 dwFlag = new int();
if (!InternetGetConnectedState(ref dwFlag, 0))
return false;
else if ((dwFlag & INTERNET_CONNECTION_LAN) != 0)
return true;
return false;
}
}
}