Deepali Joshi
Deepali Joshi

Reputation: 73

How to get PCI slot information for network adapters / NIC cards using python API like wmi on windows

On windows I want to find which network adapter in which slot. I found following powershell commands.

 Get-WmiObject -class "Win32_SystemSlot"  which gives pci slot information
   SlotDesignation : PCI1
Tag             : System Slot 0
SupportsHotPlug : False
Status          : OK
Shared          : False
PMESignal       : True
MaxDataWidth    : 8

SlotDesignation : PCI2
Tag             : System Slot 1
SupportsHotPlug : False
Status          : OK
Shared          : False
PMESignal       : True
MaxDataWidth    : 10

 Get-NetAdapterHardwareInfo 
Name                           Segment Bus Device Function Slot NumaNode PcieLinkSpeed PcieLinkWidth Version
----                           ------- --- ------ -------- ---- -------- ------------- ------------- -------
NIC4                                 0   2      0        1             0      5.0 GT/s             1 1.1
NIC1                                 0   1      0        0             0      5.0 GT/s             1 1.1
NIC3                                 0   2      0        0             0      5.0 GT/s             1 1.1
SLOT 2 Port 1                        0  66      0        0    2        1      5.0 GT/s             4 1.1
SLOT 2 Port 2                        0  66      0        1    2        1      5.0 GT/s             4 1.1 

How can I get same information using wmi library in python. I tried

import wmi
c = wmi.WMI()
network = c.Win32_NetworkAdapter()
for adapter in network:
     print(f"Network Adapter: {adapter}")

This gives a lot information about the adapter, manufacturer etc. But does not give the slot information as in powershell command Get-NetAdapterHardwareInfo above. I want to co-relate the slot info from Get-NetAdapterHardwareInfo to the PCI slot info we get from Get-WmiObject -class "Win32_SystemSlot"

So how can I get PCI slot information for a network adapter using python library like WMI or any other tool. This is the instance of Win32_NetworkAdapter

{
        AdapterType = "Ethernet 802.3";
        AdapterTypeId = 0;
        Availability = 3;
        Caption = "[00000008] Broadcom NetXtreme Gigabit Ethernet";
        ConfigManagerErrorCode = 0;
        ConfigManagerUserConfig = FALSE;
        CreationClassName = "Win32_NetworkAdapter";
        Description = "Broadcom NetXtreme Gigabit Ethernet";
        DeviceID = "8";
        GUID = "{8E574D4E-47A4-408A-B893-D42D569DE9A1}";
        Index = 8;
        Installed = TRUE;
        InterfaceIndex = 9;
        MACAddress = "C8:1F:66:F2:A3:B8";
        Manufacturer = "Broadcom";
        MaxNumberControlled = 0;
        Name = "Broadcom NetXtreme Gigabit Ethernet #4";
        NetConnectionID = "NIC3";
        NetConnectionStatus = 7;
        NetEnabled = FALSE;
        PhysicalAdapter = TRUE;
        PNPDeviceID = "PCI\\VEN_14E4&DEV_165F&SUBSYS_1F5B1028&REV_00\\0000C81F66F2A3B800";
        PowerManagementSupported = FALSE;
        ProductName = "Broadcom NetXtreme Gigabit Ethernet";
        ServiceName = "b57nd60a";
        Speed = "9223372036854775807";
        SystemCreationClassName = "Win32_ComputerSystem";
        SystemName = "WIN-IB3B2171E8I";
        TimeOfLastReset = "20240203222756.500000-480";
};

And this is the instance of Win32_SystemSlot

{
        BusNumber = 65535;
        Caption = "System Slot";
        ConnectorType = {0};
        CreationClassName = "Win32_SystemSlot";
        CurrentUsage = 3;
        Description = "System Slot";
        DeviceNumber = 80;
        FunctionNumber = 0;
        MaxDataWidth = 8;
        Name = "System Slot";
        PMESignal = TRUE;
        SegmentGroupNumber = 65535;
        Shared = FALSE;
        SlotDesignation = "PCI1";
        Status = "OK";
        SupportsHotPlug = FALSE;
        Tag = "System Slot 0";
        VccMixedVoltageSupport = {2};
};

How do I link these 2 classes to find which NIC is in which PCI slot. Thank you

Upvotes: 0

Views: 452

Answers (0)

Related Questions