如何以编程方式检测Window的网络适配器的双工状态? [英] How can I programmatically detect a Window's network adapter's duplex state?
问题描述
我正在使用WMI检测有关网络适配器状态的许多项目.我需要找出的东西包括(a)速度和(b)双工.
I am using WMI to detect a number of items about a network adapter's state. Among the things I need to find out are (a) speed and (b) duplex.
通过使用WMI和以下Python代码,我已经能够检测到网络适配器的速度:
I have been able to detect the speed of a network adapter by using WMI and the following Python code:
from pycom.client import wmi
dev_name = r"\\DEVICE\\{287EB4BB-5C2A-4108-B377-15E1D0B0E760}"
query1 = """
SELECT *
FROM MSNdis_EnumerateAdapter
WHERE DeviceName = '%s'""" % dev_name
wmi_ndis = wmi.WMI("root\\WMI")
results = wmi_ndis.ExecQuery(query1)
instance_name = results[0].InstanceName
del results
query2="""
SELECT *
FROM MSNdis_LinkSpeed
WHERE InstanceName='%s'""" % instance_name
results = wmi_ndis.ExecQuery(query2)
linkspeed = results[0].NdisLinkSpeed
del results
print instance_name, linkspeed
del instance_name
del linkspeed
del wmi_ndis
对于我想要的数据似乎有一个完美的类:MSNDis_LinkParameters.但是,此表似乎没有被填充.在Win32_NetworkAdapter中也有一些值,但也不会填充它们.
There appears to be a perfect class for the data I want: MSNDis_LinkParameters. However, this table does not appear to be populated. There are values in Win32_NetworkAdapter as well, but they are also not populated.
我很乐意使用本机C API或WMI,但是我无法进行屏幕抓取,因为该应用程序需要使用任意语言.谢谢!
I would be happy to use a native C API or WMI, but I can't do screen scraping because the application needs to work with arbitrary languages. Thanks!
推荐答案
显然,这里的根本问题是WMI提供程序的实现是由NIC供应商而不是OS处理的,因此某些NIC可能在某些时候支持某些设置(如您已经发现)别人没有.
Apparently the underlying issue here is that WMI provider implementation is handled by the NIC vendor, not the OS-- so some NICs may support some settings while (as you've discovered) others don't.
有关链接速度,请查看此,以获取某些WMI脚本可能适用于大多数NIC.
For link speed, check out this for some WMI scripts which may work on most NICs.
对于双面打印,我认为您很不走运,至少根据 topic .请看该线程中的最后一篇文章-在某些情况下,如何解决限制似乎很具体,但不适用于所有NIC.
For duplex, I think you're out of luck, at least according to topic. Look at the last post in that thread-- it seems pretty specific about how to work around the limit in some cases, but won't work for all NICs.
这篇关于如何以编程方式检测Window的网络适配器的双工状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!