https://github.com/sanketsudake/ifconfig-parser
Parse ifconfig output collected from local/remote server and retrieve values with goodies
https://github.com/sanketsudake/ifconfig-parser
ifconfig ifconfig-parser ifparser ipconfig network python python-2
Last synced: about 2 months ago
JSON representation
Parse ifconfig output collected from local/remote server and retrieve values with goodies
- Host: GitHub
- URL: https://github.com/sanketsudake/ifconfig-parser
- Owner: sanketsudake
- License: bsd-3-clause
- Created: 2016-03-25T07:56:57.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T08:45:50.000Z (over 1 year ago)
- Last Synced: 2025-04-05T10:12:24.326Z (2 months ago)
- Topics: ifconfig, ifconfig-parser, ifparser, ipconfig, network, python, python-2
- Language: Python
- Homepage: https://pypi.python.org/pypi/ifparser/
- Size: 29.3 KB
- Stars: 42
- Watchers: 3
- Forks: 10
- Open Issues: 4
-
Metadata Files:
- Readme: README.rst
Awesome Lists containing this project
README
ifconfig-parser
################.. image:: https://travis-ci.org/ssudake21/ifconfig-parser.svg?branch=master
:target: https://travis-ci.org/ssudake21/ifconfig-parserParse ifconfig output collected from local or remote server and retrieve required
interface information.Usage
=====
Install ifconfig-parser:.. code-block:: bash
pip install -U ifparser
You can access inferface information as below :
.. code-block:: python
>>> 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 :
.. code-block:: python
>>> 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:
.. code-block:: python
>>> 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, NOARP, PROMISC, POINTOPOINT, SIMPLEX, SMART, MASTER, SLAVE
- 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