Package: ifcfg
Ifcfg is a cross-platform (Windows/Unix) library for parsingifconfigandipconfigoutput in Python. It is useful for pulling information such as IP,
Netmask, MAC Address, Hostname, etc.A fallbacks toipis included for newer Unix systems w/oifconfig. Windows
systems are supported (in English) throughipconfig.Usageimport ifcfg
import json

for name, interface in ifcfg.interfaces().items():
    # do something with interface
    print interface['device']       # Device name
    print interface['inet']         # First IPv4 found
    print interface['inet4']        # List of ips
    print interface['inet6']        # List of ips
    print interface['netmask']      # Backwards compat: First netmask
    print interface['netmasks']     # List of netmasks
    print interface['broadcast']    # Backwards compat: First broadcast
    print interface['broadcasts']   # List of broadcast

default = ifcfg.default_interface()The output of ‘ifcfg.interfaces()’ dumped to JSON looks something like the
following:$ python -m ifcfg.cli | python -mjson.tool
{
    "docker0": {
        "inet": "172.17.0.1",
        "inet4": [
            "172.17.0.1"
        ],
        "ether": "01:02:9d:04:07:e3",
        "inet6": [],
        "netmask": "255.255.0.0",
        "netmasks": [
            "255.255.0.0"
        ],
        "broadcast": "172.17.255.255",
        "broadcasts": [
            "172.17.255.255"
        ],
        "prefixlens": [],
        "device": "docker0",
        "flags": "4099<UP,BROADCAST,MULTICAST> ",
        "mtu": "1500"
    },
    "enp0s25": {
        "inet": null,
        "inet4": [],
        "ether": "a0:88:b4:3d:67:7b",
        "inet6": [],
        "netmask": null,
        "netmasks": [],
        "broadcast": null,
        "broadcasts": [],
        "prefixlens": [],
        "device": "enp0s25",
        "flags": "4099<UP,BROADCAST,MULTICAST> ",
        "mtu": "1500"
    },
    "lo": {
        "inet": "127.0.0.1",
        "inet4": [
            "127.0.0.1"
        ],
        "ether": null,
        "inet6": [
            "::1"
        ],
        "netmask": "255.0.0.0",
        "netmasks": [
            "255.0.0.0"
        ],
        "broadcast": null,
        "broadcasts": [
            null
        ],
        "prefixlens": [
            "128"
        ],
        "device": "lo",
        "flags": "73<UP,LOOPBACK,RUNNING> ",
        "mtu": "65536"
    },
}DevelopmentTo bootstrap development, use a Python virtual environment, and install the dev requirements:# Install dev dependencies
pip install -r requirements_dev.txt
# Run tests locally
make testYou can also install tox and run the tests in a specific environment:pip install tox
tox -e py27Before commiting and opening PRs, ensure that you have pre-commit hooks running:pip install pre-commit
pre-commit installRelease notes0.24add support for arrow notation inet #710.23Add support for multiple netmasks, broadcast addresses, as well as ipv6 prefix lengths #670.22Python 3.7 and 3.8 support #51 #53Default interface detection on Windows #25 #56New flags for unixipcommand #610.22Python 3.7 and 3.8 support #51 #53Default interface detection on Windows #25 #56New flags for unixipcommand #610.21ForceCas locale for running commands, to ensure consistent regex patterns #470.20Throw an exception when neitheripnorifconfigcommands exist #450.19Adds support for interfaces with VLAN notation, e.g.eth2.2#40Fetch MTU values fromipcommand results #390.18Adds support for interfaces with non-alphanumeric characters, e.g.eth-int#35 and #360.17Restoreipafter regressions + add testsAdd MacOSX support foripcommand0.16Support for multiple IPv4 addresses in the new ‘inet4’ fieldPackaging cleanup0.15Support for bridged interface names #240.14Replace Python 2 syntax #210.13Further crashes on non-English Windows systems #17Known issue: Localized non-English Windows parsing does not work #180.12Fix encoding crashes on non-English Windows systems0.11After 6 beta releases, we move on from an idea that this is beta software and instead consider
it to be stable – we will probably never actually keep up with all the various ways of detecting
network properties for different systems. Anything that is incorrectly detected and can be updated,
can also be implemented and shipped as a new patch release.So let’sship early, ship ofteninstead.This release seeks to clean up the codebase (sparingly!) and introduce
Windows compatibility.Add Windows compatible parsing ofipconfigoutputHandle non-unicode terminals (Windows+Mac especially)Removing ill-definedencodingkeyword arg fromifcfg.get_parserRemoved no-op Linux Kernel 2.x parsing andkernelkeyword argRemoved classifcfg.IfcfgParser, useUnixParserinsteadAll strings are UTF-8, also in Py 2.7Only cross-platform features are now guaranteed to be in the result set:['inet', 'ether', 'inet6', 'netmask']IPv6 addresses are now stored in a list.Removed prefixlen and scopeid, as they should be added for each IPv6 address, not the
interfaceAllowifcfgto be imported despite whether or not the OS system is
recognized.Removeifcfg.excmoduleFix some interface names containing:_-characters on Linux (Sergej Vasiljev)0.10.1Fixed encoding issues, preventingdefault_interfaceto be detected0.10Support for Unix systems w/oifconfig, for instance newer Ubuntu/DebianRefactored to usesrc/hierarchyLicenseThe Ifcfg library is Open Source and is distributed under the BSD
License (three clause). Please see the LICENSE file included with this
software.