You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.3 KiB

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);
/// <summary>
/// 是否联网
/// </summary>
public static bool IsConnected()
{
System.Int32 dwFlag = new int();
if (!InternetGetConnectedState(ref dwFlag, 0))
return false;
return true;
}
/// <summary>
/// 是否采用猫联网。如果没联网,返回false
/// </summary>
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;
}
/// <summary>
/// 是否采用LAN联网。如果没联网,返回false
/// </summary>
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;
}
}
}