Skip to main content

Parse ifconfig output and retrieve values with goodies

Project description

Parse ifconfig output collected from local or remote server and retrieve required interface information.

Usage

Install ifconfig-parser:

pip install -U ifparser

You can access inferface information as below :

>>> import commands
>>> from ifparser import Ifcfg
>>> ifdata = Ifcfg(commands.getoutput('ifconfig -a'))
>>> ifdata.interfaces
['lo', 'docker0', 'eth0']
>>> eth0 = ifdata.get_interface('eth0')
>>> eth0.BROADCAST
True
>>> eth0.hwaddr, eth0.mtu, eth0.ip, eth0.UP
('08:00:27:1f:d8:b0', '1500', '10.0.2.15', True)

You can query for intefaces on particular parameter :

 >>> ifdata.get(itype='Ethernet')
 [obj-docker0, obj-eth0]
 >>> ifdata.get(UP=True)
[obj-lo, obj-docker0, obj-eth0]

Get all interface parameters with get_values. Following dictionary contains all possible values:

>>> eth0 = ifdata.get_interface('eth0')
>>> eth0.get_values()
{'BROADCAST': True,
 'LOOPBACK': False,
 'MULTICAST': True,
 'RUNNING': True,
 'UP': True,
 'bcast': '10.10.2.255',
 'hwaddr': 'FF:FF:27:1f:d8:b0',
 'interface': 'eth0',
 'ip': '10.10.2.15',
 'itype': 'Ethernet',
 'mask': '255.255.255.0',
 'mtu': '1500',
 'rxbytes': '547873',
 'rxpkts': '628',
 'txbytes': '50826',
 'txpkts': '424'}

List of parameters for interface:

  • BROADCAST, LOOPBACK, MULTICAST, RUNNING, UP, DYNAMIC

  • interface - Interface name, itype - Interface Type

  • ip - IP, bcast - Broadcast, mask - Mask

  • hwaddr - MAC address, mtu - MTU

  • rxbytes - Received Bytes, rxpkts - Received Packets

  • txbytes - Sent Bytes, txpkts - Sent Packets

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ifparser-0.5.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ifparser-0.5.0-py2-none-any.whl (7.6 kB view details)

Uploaded Python 2

File details

Details for the file ifparser-0.5.0.tar.gz.

File metadata

  • Download URL: ifparser-0.5.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for ifparser-0.5.0.tar.gz
Algorithm Hash digest
SHA256 fd1f7554f4d224bce13179bbe0fa34db143586c648649c0a7959bb5f8e63bb7a
MD5 0d74df763fc04fdc2ad276788bfa8bd8
BLAKE2b-256 f6f961eaed204cf206600c445811120a7a9f0a7ee8f4513fa29aa11f5ee55833

See more details on using hashes here.

File details

Details for the file ifparser-0.5.0-py2-none-any.whl.

File metadata

File hashes

Hashes for ifparser-0.5.0-py2-none-any.whl
Algorithm Hash digest
SHA256 49f84369f6abcb821900b4e0f31ecebf7897c79794cd988d5c38828ebfea56ea
MD5 2a65f127f5c1119cbd8acaa973cd115c
BLAKE2b-256 1b2498879f5a7c0b59c51448092ba189d76ed737c604e5eacbbcd1e8c85409b7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page