.. 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
.
::
import 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"
},
}
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
0.23
0.22
ip
command #610.22
ip
command #610.21
C
as locale for running commands, to ensure consistent regex patterns #470.20
ip
nor ifconfig
commands exist #450.19
eth2.2
#40ip
command results #390.18
eth-int
#35 and #360.17
ip
after regressions + add testsip
command0.16
0.15
0.14
0.13
0.12
0.11
After 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's ship early, ship often instead.
This release seeks to clean up the codebase (sparingly!) and introduce Windows compatibility.
ipconfig
outputencoding
keyword arg from ifcfg.get_parser
kernel
keyword argifcfg.IfcfgParser
, use UnixParser
instead['inet', 'ether', 'inet6', 'netmask']
ifcfg
to be imported despite whether or not the OS system is
recognized.ifcfg.exc
module:_-
characters on Linux (Sergej Vasiljev)0.10.1
default_interface
to be detected0.10
ifconfig
, for instance newer Ubuntu/Debiansrc/
hierarchyThe Ifcfg library is Open Source and is distributed under the BSD License (three clause). Please see the LICENSE file included with this software.