Python WMI – Get network adapter information

In this post we will be creating a Python script that will retrieve system network adapter information for the local machine. To do this we will be using the ‘WMI’ module, short for Windows Management Instrumentation. This module allows access to most information about a computer system.

To install the WMI module run the following command.

pip install WMI

See the sample of Python code where we utilize the WMI module to get the network adapter information.

We start by connecting to the windows system and then query the machines adapter information.

import wmi

c = wmi.WMI()

network = c.Win32_NetworkAdapterConfiguration()

for adapter in network:
    if adapter.IPEnabled:
        print(f"Network Adapter: {adapter.Description}")
        print(f"IP Address: {adapter.IPAddress[0]}")
        print(f"Subnet Mask: {adapter.IPSubnet[0]}")

Take a look at some of our other content around the Python programming language by clicking here.

Leave a Reply