1

尝试检测何时在 Internet 连接上使用强制门户,即连接在咖啡店的笔记本电脑。

尝试使用网络列表管理器 COM 对象来实现这一点:

NETWORKLIST.NetworkListManager _networkListManager = new NetworkListManager();
foreach (INetworkConnection net in _networkListManager.GetNetworkConnections())
{                
    if (net.GetConnectivity().HasFlag(NLM_CONNECTIVITY.NLM_CONNECTIVITY_IPV4_INTERNET) == true)
      {
           // Check if we are connected by a captive web portal
           // using NLM_INTERNET_CONNECTIVITY_WEBHIJACK
      }                                
 }

根据这里的文档:http: //msdn.microsoft.com/en-us/library/windows/desktop/aa370750 (v=vs.85).aspx

“可以通过使用 INetwork 或 INetworkConnection 接口的 IPropertyBag 接口查询 NA_InternetConnectivityV4 或 NA_InternetConnectivityV6 属性来检索这些连接标志”

我似乎不存在 NA_InternetConnectivityV4 枚举(不完整的实现),或者我不知道如何使用它们。

有没有人实际使用过这个或对检测强制门户何时使用的方法有想法?

4

2 回答 2

1

这不是 C#,但我发现这些 API 正在使用 C++

pNetworkListManager->GetNetworks (NLM_ENUM_NETWORK_CONNECTED, &pEnum) INetwork *pINetwork;

//Should actually loop through the possible networks.
HRESULT hr = pEnum->Next(1, &pINetwork, nullptr);

IPropertyBag *pNetworkPropertyBag;
HRESULT hrQueryInterface = pINetwork->QueryInterface(IID_IPropertyBag, (LPVOID*)&pNetworkPropertyBag);
if (SUCCEEDED(hrQueryInterface 1) && pNetworkPropertyBag != nullptr)
{
    NLM_CONNECTIVITY networkConnectivity;
    VARIANT variantConnectivity;

    if (SUCCEEDED(pINetwork->GetConnectivity(&networkConnectivity)))
    {
        if ((networkConnectivity & 
        NLM_CONNECTIVITY_IPV4_INTERNET) == NLM_CONNECTIVITY_IPV4_INTERNET)
        {
            VariantInit(&variantConnectivity);
            if (SUCCEEDED(pNetworkPropertyBag->Read(NA_InternetConnectivityV4, &variantConnectivity, nullptr)) && (V_UINT(&variantConnectivity) & NLM_INTERNET_CONNECTIVITY_WEBHIJACK) == NLM_INTERNET_CONNECTIVITY_WEBHIJACK)
            {
                //Captive Portal detected
            }
            VariantClear(&variantConnectivity);
    }
}

检查此以获取完整的详细信息:http: //www.codeproject.com/Articles/1088221/Captive-Portal-Detection-with-Windows-APIs

于 2016-03-29T04:25:45.357 回答
0

关闭这个,调查显示 NA_InternetConnectivityV4 枚举不存在并且 MSDN 文档不正确。

于 2013-12-10T09:00:21.297 回答