views:

1594

answers:

3

Hi,

My dream is to query the network card setting on WIN using python. What I need is to query if the NIC is set to full duplex and if it is set to 1000Mb full. WMI class named Win32_NetworkAdapterConfiguration doesn't provide these info.Alternatively a cmd command line sulution can be insteresting as well (via calling from python).

Thnx

+1  A: 

This really isn't a python question. Anything you can do with the win32api, You can do through Python, so the question here is just about the windows API and it doesn't make any difference that you happen to be invoking them from Python. Asking without the Python tag might get better response, actually, because people will look who know how to do it in another language, which would be using the same API.

ironfroggy
A: 

Yes! This really isn't a python question. Anyway take a look at: List Network Adapter Configuration Properties

and brows down into the python@microsoft scripts repository maybe helpfull for your problem.

You can also find usefull in python:

>>> import os
>>> f= os.popen('<type your dos command>')
>>> s = f.read()
>>> print s
DrFalk3n
A: 

As @ironfroggy said, this is not specific to Python, but a general Windows question.

When we wanted to programmatically find the speed and duplex settings on network cards, it was very difficult. In the end we resorted to wandering through the registry, which has a different structure depending on the vendor of your NIC.

It goes something like this; apologies for any errors:

  1. Find HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Network and look for GUIDs that have the data "Network Adapters". Call this <GUID1>.
  2. Underneath the <GUID1> key is another GUID for each NIC. Call one of them <GUID2>.
  3. Go to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\<GUID1>.
  4. Iterate through its keys (they look like 0000, 0001, 0002, etc.) until you find one that has the value NetCfgInstanceId equal to <GUID2>.
  5. Underneath here, look for a subkey dependent on NIC vendor. Some we have defined are:
    • Ndi\Params
    • Ndi\savedParams
    • BRCMndi\params
  6. Under there, iterate through the keys until you find one with a value called ParamDesc whose data contains the words "speed" and "duplex". Remember the key name and called it <SpeedDuplexParamName>.
  7. Underneath <SpeedDuplexParamName> there is an enum key, which matches numbers to descriptions like "Auto-detect" and "100 Mb Full".
  8. Go back up a few levels to where you found NetCfgInstanceId. Near there you can see the current value as an enumeration. For one example here the value name was RequestedMediaType and the value was 6.
  9. Look up the enumeration value to find the speed and duplex setting.

I see @DrFalk3n has linked to a Microsoft article that might say the same, but I'll leave this here in case it is helpful.

Paul Stephenson