<commit_before>Python cross-platform network interface discovery
=================================================

.. image:: https://badge.fury.io/py/ifcfg.svg
   :target: https://pypi.python.org/pypi/ifcfg/
.. image:: https://travis-ci.org/ftao/python-ifcfg.svg
  :target: https://travis-ci.org/ftao/python-ifcfg
.. image:: http://codecov.io/github/ftao/python-ifcfg/coverage.svg?branch=master
  :target: http://codecov.io/github/ftao/python-ifcfg?branch=master

Ifcfg is a cross-platform (Windows/Unix) library for parsing ``ifconfig`` and
``ipconfig`` output in Python. It is useful for pulling information such as IP,
Netmask, MAC Address, Hostname, etc.

A fallbacks to ``ip`` is included for newer Unix systems w/o ``ifconfig``. Windows
systems are supported (in English) through ``ipconfig``.

Usage
-----

::

    import ifcfg
    import json

    for name, interface in ifcfg.interfaces().items():
        # do something with interface
        print interface['device']
        print interface['inet']         # First IPv4 found
        print interface['inet4']        # List of ips
        print interface['inet6']
        print interface['netmask']
        print interface['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
    {
        "eth0": {
            "broadcast": "172.16.217.255",
            "ether": "00:0c:29:0c:da:5d",
            "flags": "4163<up,broadcast,running,multicast> ",
            "hostname": "derks-vm.local",
            "inet": "172.16.217.10",
            "inet4": ["172.16.217.10"],
            "inet6": ["fe80::20c:29ff:fe0c:da5d"],
            "mtu": "1500",
            "name": "eth0",
            "netmask": "255.255.255.0",
        },
        "lo": {
            "ether": null,
            "flags": "73<up,loopback,running> ",
            "hostname": "localhost",
            "inet": "127.0.0.1",
            "inet4": ["127.0.0.1"],
            "inet6": ["::1"],
            "mtu": "16436",
            "name": "lo",
            "netmask": "255.0.0.0",
        },
        "virbr0": {
            "broadcast": "192.168.122.255",
            "ether": "52:54:00:5b:70:0d",
            "flags": "4099<up,broadcast,multicast> ",
            "hostname": "derks-vm.local",
            "inet": "192.168.122.1",
            "inet4": ["192.168.122.1"],
            "inet6": [],
            "mtu": "1500",
            "name": "virbr0",
            "netmask": "255.255.255.0",
        }
    }


Development
-----------

To 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 test

You can also install tox and run the tests in a specific environment::

    pip install tox
    tox -e py27

Before commiting and opening PRs, ensure that you have pre-commit hooks running::

    pip install pre-commit
    pre-commit install


Release notes
-------------

0.21b1
______

* Force `C` as locale for running commands, to ensure consistent regex patterns #47

0.20
____

* Throw an exception when neither `ip` nor `ifconfig` commands exist #45

0.19
____

* Adds support for interfaces with VLAN notation, e.g. `eth2.2` #40
* Fetch MTU values from `ip` command results #39

0.18
____<commit_msg>Bump also README<commit_after>Python cross-platform network interface discovery
=================================================

.. image:: https://badge.fury.io/py/ifcfg.svg
   :target: https://pypi.python.org/pypi/ifcfg/
.. image:: https://travis-ci.org/ftao/python-ifcfg.svg
  :target: https://travis-ci.org/ftao/python-ifcfg
.. image:: http://codecov.io/github/ftao/python-ifcfg/coverage.svg?branch=master
  :target: http://codecov.io/github/ftao/python-ifcfg?branch=master

Ifcfg is a cross-platform (Windows/Unix) library for parsing ``ifconfig`` and
``ipconfig`` output in Python. It is useful for pulling information such as IP,
Netmask, MAC Address, Hostname, etc.

A fallbacks to ``ip`` is included for newer Unix systems w/o ``ifconfig``. Windows
systems are supported (in English) through ``ipconfig``.

Usage
-----

::

    import ifcfg
    import json

    for name, interface in ifcfg.interfaces().items():
        # do something with interface
        print interface['device']
        print interface['inet']         # First IPv4 found
        print interface['inet4']        # List of ips
        print interface['inet6']
        print interface['netmask']
        print interface['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
    {
        "eth0": {
            "broadcast": "172.16.217.255",
            "ether": "00:0c:29:0c:da:5d",
            "flags": "4163<up,broadcast,running,multicast> ",
            "hostname": "derks-vm.local",
            "inet": "172.16.217.10",
            "inet4": ["172.16.217.10"],
            "inet6": ["fe80::20c:29ff:fe0c:da5d"],
            "mtu": "1500",
            "name": "eth0",
            "netmask": "255.255.255.0",
        },
        "lo": {
            "ether": null,
            "flags": "73<up,loopback,running> ",
            "hostname": "localhost",
            "inet": "127.0.0.1",
            "inet4": ["127.0.0.1"],
            "inet6": ["::1"],
            "mtu": "16436",
            "name": "lo",
            "netmask": "255.0.0.0",
        },
        "virbr0": {
            "broadcast": "192.168.122.255",
            "ether": "52:54:00:5b:70:0d",
            "flags": "4099<up,broadcast,multicast> ",
            "hostname": "derks-vm.local",
            "inet": "192.168.122.1",
            "inet4": ["192.168.122.1"],
            "inet6": [],
            "mtu": "1500",
            "name": "virbr0",
            "netmask": "255.255.255.0",
        }
    }


Development
-----------

To 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 test

You can also install tox and run the tests in a specific environment::

    pip install tox
    tox -e py27

Before commiting and opening PRs, ensure that you have pre-commit hooks running::

    pip install pre-commit
    pre-commit install


Release notes
-------------

0.21
____

* Force `C` as locale for running commands, to ensure consistent regex patterns #47

0.20
____

* Throw an exception when neither `ip` nor `ifconfig` commands exist #45

0.19
____

* Adds support for interfaces with VLAN notation, e.g. `eth2.2` #40
* Fetch MTU values from `ip` command results #39

0.18
____
{'fraction_non_alphanumeric': 0.16322344322344323, 'fraction_numerical': 0.054945054945054944, 'mean_word_length': 2.3087736306349975, 'pattern_counts': {'":': 66, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 22, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1612813', 'n_tokens_mistral': 2354, 'n_tokens_neox': 2129, 'n_words': 574}