Ifcfg is a cross-platform Python library designed for parsing the output of system network configuration commands like `ifconfig` (Unix/Linux/macOS) and `ipconfig` (Windows). It provides a structured way to access network interface information such as IP addresses, netmasks, MAC addresses, and hostnames. The library includes a fallback mechanism to the `ip` command for modern Unix systems where `ifconfig` might be deprecated or unavailable. Currently at version 0.24, it sees active maintenance with several releases per year to address compatibility and add features.
pip install ifcfgVerified import paths — ran on the pinned version, not inferred.
This quickstart retrieves all network interfaces and prints key details like MAC, IPv4, IPv6, netmask, and MTU. It then attempts to access specific details for a commonly named interface (e.g., 'eth0' on Linux or 'en0' on macOS).
Ensure that `ifconfig` (or equivalent) or `ip` utilities are installed and accessible in the system's PATH. For Linux, `iproute2` (which provides `ip`) is generally preferred.
Upgrade to `ifcfg` 0.21 or newer. If issues persist, verify that your system's `ifconfig` or `ip` commands produce English-like output when run under a 'C' locale (e.g., `LC_ALL=C ifconfig`).
When retrieving IPv4 addresses, iterate through `interface_data.get('inet4', [])` instead of relying solely on `interface_data.get('inet')`.This often points to an unexpected system command output format. Ensure your system's `ifconfig`/`ip` tools are standard versions. If running on a non-standard Linux/Unix distribution or an older/newer OS version, consider submitting an issue to the `ifcfg` GitHub repository with your `ifconfig`/`ip` output for review. Manually inspecting the raw command output might reveal discrepancies.
Install the necessary network utilities for your operating system (e.g., `net-tools` for `ifconfig` or `iproute2` for `ip` on Linux, which is usually installed by default). Ensure the directory containing the command (e.g., `/sbin` or `/usr/sbin`) is in your system's PATH environment variable.
Always use the `.get()` method when accessing interface dictionary keys, providing a default value (e.g., `interface_data.get('inet', 'N/A')` or `interface_data.get('inet4', [])`). If fields are unexpectedly missing, review the system's `ifconfig`/`ip` command output manually for that interface to ensure the data is present and correctly formatted for `ifcfg` to parse.No dependency data recorded yet.