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

48 lines
1.2 KiB
C#

9 months ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
namespace POSV.Utils
{
public static class NetworkUtils
{
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
/// <summary>
/// 指示是否有任何可用的网络连接。
/// </summary>
/// <returns></returns>
public static bool IsNetworkLink()
{
bool result = NetworkInterface.GetIsNetworkAvailable();
logger.Debug("GetIsNetworkAvailable <{0}>",result);
return result;
}
/// <summary>
/// 检测电脑是否联网
/// </summary>
/// <returns>true表示联网</returns>
public static bool IsConnectedToInternet()
{
int i = 0;
if (WindowsAPI.InternetGetConnectedState(out i , 0))
{
logger.Debug("InternetGetConnectedState <{0}>" , i);
//已联网
return true;
}
else
{
logger.Debug("InternetGetConnectedState <{0}>" , i);
//未联网
return false;
}
}
}
}