简体   繁体   English

确定是否有人用C ++硬连线到路由器

[英]Determine whether someone is hard-wired to router in C++

We are trying to come up with the best way to detect if a user is hard-wired to their router in a C++ program being developed in Qt. 我们正在尝试提出一种最佳方法,以检测用户是否在Qt中开发的C ++程序中硬连线到其路由器。 It is okay if they are on WiFi also, but there needs to be a hard-wire present, as well. 如果他们也可以使用WiFi,也可以,但是也需要有硬连线。

This would only need to work on Windows but it would need to work on XP, Vista, 7, 8, and 8.1. 这仅需要在Windows上运行,但需要在XP,Vista,7、8和8.1上运行。

We tried the QNetworkConfiguration::BearerType which was promising but didn't seem to give any definitive results. 我们尝试了QNetworkConfiguration :: BearerType,它很有希望但似乎没有给出任何明确的结果。

Has anyone ever done this or have an idea on how to? 有没有人做过或者有关于如何做的想法? What is the best way? 什么是最好的方法? And if the answer involves QNetworkConfiguration, how do you figure it for the possibility that someone may be hard wired thru the Local Area Connection? 如果答案涉及QNetworkConfiguration,您如何看待它可能导致某人通过本地连接硬连线?

EDIT FOR CLARITY We employ work-from-home sales agents that use a softphone to make calls. 编辑清晰度我们雇用在家工作的销售代理商,他们使用软件电话进行呼叫。 We require them to be hard-wired to their router for better call quality. 我们要求将它们硬连线到路由器,以提高通话质量。 Since they are work from home, it is very hard to keep them plugged in without constant monitoring. 由于它们是在家工作,因此很难在不进行持续监控的情况下将其插入电源。 They use a custom interface that we have control over and would like to be able to do this check before activating the interface, as well as periodically re-checking to ensure they stay plugged in. 他们使用我们可以控制的自定义界面,并希望能够在激活界面之前进行此检查,并定期重新检查以确保它们保持插入状态。

No, this is not possible. 不,这是不可能的。 A computer could be connected through a chain of a dozen switches (or worse, hubs) or a mile of untwisted pair cabling and there is no way you could specifically check that through software. 一台计算机可能通过一打十二个交换机(或更糟的是,集线器)或一英里的非双绞线电缆连接在一起,因此您无法通过软件专门进行检查。

What you can do instead is measure the quality of the connection (ping time to default gateway and/or some known good external host, packet loss to same, etc). 相反,您可以做的是测量连接的质量(到默认网关和/或某个已知的良好外部主机的ping时间,到相同主机的数据包丢失等)。

As stated by Andrew (+1!) you should check the quality of the connection, more than the type/topology. 如安德鲁(+1!)所述,您应该检查连接的质量,而不是类型/拓扑。 That could be quite pointless since (i) topology can vary a lot and (ii) several other factors can affect the connection, apart from the used bearer. 这可能是毫无意义,因为(ⅰ)拓扑结构可以从所使用的承载有很大的差异,和(ii)其它几个因素会影响的连接,开。

That said, QNetworkConfiguration is still the answer to the bearer checking question but via the QNetworkConfigurationManager class. 也就是说, QNetworkConfiguration仍然是承载检查问题的答案,但通过QNetworkConfigurationManager类。 Indeed, a valid QNetworkConfiguration can be available to you even if the corresponding (wired or not wired) connection is not available, at the moment. 的确,即使此时相应的(有线或未有线)连接不可用, 可以使用有效的QNetworkConfiguration

You should code something like this: 您应该编写如下代码:

QNetworkConfiguration cfg;    
QNetworkConfigurationManager ncm;
auto nc = ncm.allConfigurations(QNetworkConfiguration::Active);   //ACTIVE ONES

for (auto &x : nc)
{
    if (x.bearerType() == QNetworkConfiguration::BearerEthernet)
    {
        cfg = x;
        // other stuff that pleases you
    }
}

Mind that the results are somewhat frozen to the time the QNetworkConfigurationManager was created. 请注意,结果在某种程度上会冻结到创建QNetworkConfigurationManager的时间。 To update the list, before skimming it, you can call the (time consuming) updateConfigurations() . 要更新列表,在浏览之前,可以调用(耗时) updateConfigurations()

Finally, by exploiting the configurationChanged(const QNetworkConfiguration & config) signal, you can track down status changes for your LAN connection. 最后,通过利用configurationChanged(const QNetworkConfiguration & config)信号,您可以跟踪LAN连接的状态更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM