2021-04-09 10:36:42 -07:00
|
|
|
[Home](https://kellyjonbrazil.github.io/jc/)
|
2022-01-25 17:07:47 -08:00
|
|
|
<a id="jc.parsers.ifconfig"></a>
|
2020-07-30 16:20:24 -07:00
|
|
|
|
2019-11-11 18:30:46 -08:00
|
|
|
# jc.parsers.ifconfig
|
2022-01-25 17:07:47 -08:00
|
|
|
|
2020-08-05 16:51:58 -07:00
|
|
|
jc - JSON CLI output utility `ifconfig` command output parser
|
|
|
|
|
|
|
|
Note: No `ifconfig` options are supported.
|
2019-11-11 18:30:46 -08:00
|
|
|
|
2020-08-05 13:32:59 -07:00
|
|
|
Usage (cli):
|
2019-12-12 09:47:14 -08:00
|
|
|
|
2022-01-25 17:07:47 -08:00
|
|
|
$ ifconfig | jc --ifconfig
|
2020-08-05 16:51:58 -07:00
|
|
|
|
2022-01-25 17:07:47 -08:00
|
|
|
or
|
2019-11-11 18:30:46 -08:00
|
|
|
|
2022-01-25 17:07:47 -08:00
|
|
|
$ jc ifconfig
|
2019-11-11 18:30:46 -08:00
|
|
|
|
2020-08-05 13:32:59 -07:00
|
|
|
Usage (module):
|
|
|
|
|
2022-01-25 17:07:47 -08:00
|
|
|
import jc
|
|
|
|
result = jc.parse('ifconfig', ifconfig_command_output)
|
2022-01-18 15:38:03 -08:00
|
|
|
|
2022-01-25 17:07:47 -08:00
|
|
|
or
|
2022-01-18 15:38:03 -08:00
|
|
|
|
2022-01-25 17:07:47 -08:00
|
|
|
import jc.parsers.ifconfig
|
|
|
|
result = jc.parsers.ifconfig.parse(ifconfig_command_output)
|
2020-08-05 13:32:59 -07:00
|
|
|
|
2021-04-08 12:42:01 -07:00
|
|
|
Schema:
|
|
|
|
|
2022-01-25 17:07:47 -08:00
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": string,
|
|
|
|
"flags": integer,
|
|
|
|
"state": [
|
|
|
|
string
|
|
|
|
],
|
|
|
|
"mtu": integer,
|
|
|
|
"ipv4_addr": string,
|
|
|
|
"ipv4_mask": string,
|
|
|
|
"ipv4_bcast": string,
|
|
|
|
"ipv6_addr": string,
|
|
|
|
"ipv6_mask": integer,
|
|
|
|
"ipv6_scope": string,
|
|
|
|
"mac_addr": string,
|
|
|
|
"type": string,
|
|
|
|
"rx_packets": integer,
|
|
|
|
"rx_bytes": integer,
|
|
|
|
"rx_errors": integer,
|
|
|
|
"rx_dropped": integer,
|
|
|
|
"rx_overruns": integer,
|
|
|
|
"rx_frame": integer,
|
|
|
|
"tx_packets": integer,
|
|
|
|
"tx_bytes": integer,
|
|
|
|
"tx_errors": integer,
|
|
|
|
"tx_dropped": integer,
|
|
|
|
"tx_overruns": integer,
|
|
|
|
"tx_carrier": integer,
|
|
|
|
"tx_collisions": integer,
|
|
|
|
"metric": integer
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
**Examples**:
|
|
|
|
|
|
|
|
|
|
|
|
$ ifconfig | jc --ifconfig -p
|
|
|
|
[
|
|
|
|
{
|
|
|
|
- `"name"` - "ens33",
|
|
|
|
- `"flags"` - 4163,
|
|
|
|
- `"state"` - [
|
|
|
|
"UP",
|
|
|
|
"BROADCAST",
|
|
|
|
"RUNNING",
|
|
|
|
"MULTICAST"
|
|
|
|
],
|
|
|
|
- `"mtu"` - 1500,
|
|
|
|
- `"ipv4_addr"` - "192.168.71.137",
|
|
|
|
- `"ipv4_mask"` - "255.255.255.0",
|
|
|
|
- `"ipv4_bcast"` - "192.168.71.255",
|
|
|
|
- `"ipv6_addr"` - "fe80::c1cb:715d:bc3e:b8a0",
|
|
|
|
- `"ipv6_mask"` - 64,
|
|
|
|
- `"ipv6_scope"` - "0x20",
|
|
|
|
- `"mac_addr"` - "00:0c:29:3b:58:0e",
|
|
|
|
- `"type"` - "Ethernet",
|
|
|
|
- `"rx_packets"` - 8061,
|
|
|
|
- `"rx_bytes"` - 1514413,
|
|
|
|
- `"rx_errors"` - 0,
|
|
|
|
- `"rx_dropped"` - 0,
|
|
|
|
- `"rx_overruns"` - 0,
|
|
|
|
- `"rx_frame"` - 0,
|
|
|
|
- `"tx_packets"` - 4502,
|
|
|
|
- `"tx_bytes"` - 866622,
|
|
|
|
- `"tx_errors"` - 0,
|
|
|
|
- `"tx_dropped"` - 0,
|
|
|
|
- `"tx_overruns"` - 0,
|
|
|
|
- `"tx_carrier"` - 0,
|
|
|
|
- `"tx_collisions"` - 0,
|
|
|
|
- `"metric"` - null
|
|
|
|
},
|
|
|
|
{
|
|
|
|
- `"name"` - "lo",
|
|
|
|
- `"flags"` - 73,
|
|
|
|
- `"state"` - [
|
|
|
|
"UP",
|
|
|
|
"LOOPBACK",
|
|
|
|
"RUNNING"
|
|
|
|
],
|
|
|
|
- `"mtu"` - 65536,
|
|
|
|
- `"ipv4_addr"` - "127.0.0.1",
|
|
|
|
- `"ipv4_mask"` - "255.0.0.0",
|
|
|
|
- `"ipv4_bcast"` - null,
|
|
|
|
- `"ipv6_addr"` - "::1",
|
|
|
|
- `"ipv6_mask"` - 128,
|
|
|
|
- `"ipv6_scope"` - "0x10",
|
|
|
|
- `"mac_addr"` - null,
|
|
|
|
- `"type"` - "Local Loopback",
|
|
|
|
- `"rx_packets"` - 73,
|
|
|
|
- `"rx_bytes"` - 6009,
|
|
|
|
- `"rx_errors"` - 0,
|
|
|
|
- `"rx_dropped"` - 0,
|
|
|
|
- `"rx_overruns"` - 0,
|
|
|
|
- `"rx_frame"` - 0,
|
|
|
|
- `"tx_packets"` - 73,
|
|
|
|
- `"tx_bytes"` - 6009,
|
|
|
|
- `"tx_errors"` - 0,
|
|
|
|
- `"tx_dropped"` - 0,
|
|
|
|
- `"tx_overruns"` - 0,
|
|
|
|
- `"tx_carrier"` - 0,
|
|
|
|
- `"tx_collisions"` - 0,
|
|
|
|
- `"metric"` - null
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
$ ifconfig | jc --ifconfig -p -r
|
|
|
|
[
|
|
|
|
{
|
|
|
|
- `"name"` - "ens33",
|
|
|
|
- `"flags"` - "4163",
|
|
|
|
- `"state"` - "UP,BROADCAST,RUNNING,MULTICAST",
|
|
|
|
- `"mtu"` - "1500",
|
|
|
|
- `"ipv4_addr"` - "192.168.71.137",
|
|
|
|
- `"ipv4_mask"` - "255.255.255.0",
|
|
|
|
- `"ipv4_bcast"` - "192.168.71.255",
|
|
|
|
- `"ipv6_addr"` - "fe80::c1cb:715d:bc3e:b8a0",
|
|
|
|
- `"ipv6_mask"` - "64",
|
|
|
|
- `"ipv6_scope"` - "0x20",
|
|
|
|
- `"mac_addr"` - "00:0c:29:3b:58:0e",
|
|
|
|
- `"type"` - "Ethernet",
|
|
|
|
- `"rx_packets"` - "8061",
|
|
|
|
- `"rx_bytes"` - "1514413",
|
|
|
|
- `"rx_errors"` - "0",
|
|
|
|
- `"rx_dropped"` - "0",
|
|
|
|
- `"rx_overruns"` - "0",
|
|
|
|
- `"rx_frame"` - "0",
|
|
|
|
- `"tx_packets"` - "4502",
|
|
|
|
- `"tx_bytes"` - "866622",
|
|
|
|
- `"tx_errors"` - "0",
|
|
|
|
- `"tx_dropped"` - "0",
|
|
|
|
- `"tx_overruns"` - "0",
|
|
|
|
- `"tx_carrier"` - "0",
|
|
|
|
- `"tx_collisions"` - "0",
|
|
|
|
- `"metric"` - null
|
|
|
|
},
|
|
|
|
{
|
|
|
|
- `"name"` - "lo",
|
|
|
|
- `"flags"` - "73",
|
|
|
|
- `"state"` - "UP,LOOPBACK,RUNNING",
|
|
|
|
- `"mtu"` - "65536",
|
|
|
|
- `"ipv4_addr"` - "127.0.0.1",
|
|
|
|
- `"ipv4_mask"` - "255.0.0.0",
|
|
|
|
- `"ipv4_bcast"` - null,
|
|
|
|
- `"ipv6_addr"` - "::1",
|
|
|
|
- `"ipv6_mask"` - "128",
|
|
|
|
- `"ipv6_scope"` - "0x10",
|
|
|
|
- `"mac_addr"` - null,
|
|
|
|
- `"type"` - "Local Loopback",
|
|
|
|
- `"rx_packets"` - "73",
|
|
|
|
- `"rx_bytes"` - "6009",
|
|
|
|
- `"rx_errors"` - "0",
|
|
|
|
- `"rx_dropped"` - "0",
|
|
|
|
- `"rx_overruns"` - "0",
|
|
|
|
- `"rx_frame"` - "0",
|
|
|
|
- `"tx_packets"` - "73",
|
|
|
|
- `"tx_bytes"` - "6009",
|
|
|
|
- `"tx_errors"` - "0",
|
|
|
|
- `"tx_dropped"` - "0",
|
|
|
|
- `"tx_overruns"` - "0",
|
|
|
|
- `"tx_carrier"` - "0",
|
|
|
|
- `"tx_collisions"` - "0",
|
|
|
|
- `"metric"` - null
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
<a id="jc.parsers.ifconfig.info"></a>
|
|
|
|
|
|
|
|
## info Objects
|
|
|
|
|
2019-12-14 23:35:42 -08:00
|
|
|
```python
|
2022-01-25 17:07:47 -08:00
|
|
|
class info()
|
2019-12-14 23:35:42 -08:00
|
|
|
```
|
2022-01-25 17:07:47 -08:00
|
|
|
|
2021-04-08 12:42:01 -07:00
|
|
|
Provides parser metadata (version, author, etc.)
|
2020-05-01 14:57:50 -07:00
|
|
|
|
2022-01-25 17:07:47 -08:00
|
|
|
<a id="jc.parsers.ifconfig._IfconfigParser"></a>
|
|
|
|
|
|
|
|
## \_IfconfigParser Objects
|
|
|
|
|
|
|
|
```python
|
|
|
|
class _IfconfigParser(object)
|
|
|
|
```
|
|
|
|
|
|
|
|
ifconfig parser module written by threeheadedknight@protonmail.com
|
|
|
|
|
|
|
|
<a id="jc.parsers.ifconfig._IfconfigParser.__init__"></a>
|
|
|
|
|
|
|
|
#### \_\_init\_\_
|
|
|
|
|
|
|
|
```python
|
|
|
|
def __init__(console_output)
|
|
|
|
```
|
|
|
|
|
|
|
|
**Arguments**:
|
|
|
|
|
|
|
|
- `console_output`:
|
|
|
|
|
|
|
|
<a id="jc.parsers.ifconfig._IfconfigParser.list_interfaces"></a>
|
|
|
|
|
|
|
|
#### list\_interfaces
|
|
|
|
|
|
|
|
```python
|
|
|
|
def list_interfaces()
|
|
|
|
```
|
|
|
|
|
|
|
|
<a id="jc.parsers.ifconfig._IfconfigParser.count_interfaces"></a>
|
|
|
|
|
|
|
|
#### count\_interfaces
|
|
|
|
|
|
|
|
```python
|
|
|
|
def count_interfaces()
|
|
|
|
```
|
|
|
|
|
|
|
|
<a id="jc.parsers.ifconfig._IfconfigParser.filter_interfaces"></a>
|
|
|
|
|
|
|
|
#### filter\_interfaces
|
|
|
|
|
|
|
|
```python
|
|
|
|
def filter_interfaces(**kwargs)
|
|
|
|
```
|
|
|
|
|
|
|
|
**Arguments**:
|
|
|
|
|
|
|
|
- `kwargs`:
|
|
|
|
|
|
|
|
<a id="jc.parsers.ifconfig._IfconfigParser.get_interface"></a>
|
|
|
|
|
|
|
|
#### get\_interface
|
|
|
|
|
|
|
|
```python
|
|
|
|
def get_interface(name)
|
|
|
|
```
|
|
|
|
|
|
|
|
**Arguments**:
|
|
|
|
|
|
|
|
- `name`:
|
|
|
|
|
|
|
|
<a id="jc.parsers.ifconfig._IfconfigParser.get_interfaces"></a>
|
|
|
|
|
|
|
|
#### get\_interfaces
|
|
|
|
|
|
|
|
```python
|
|
|
|
def get_interfaces()
|
|
|
|
```
|
|
|
|
|
|
|
|
<a id="jc.parsers.ifconfig._IfconfigParser.is_available"></a>
|
|
|
|
|
|
|
|
#### is\_available
|
|
|
|
|
|
|
|
```python
|
|
|
|
def is_available(name)
|
|
|
|
```
|
|
|
|
|
|
|
|
**Arguments**:
|
|
|
|
|
|
|
|
- `name`:
|
|
|
|
|
|
|
|
<a id="jc.parsers.ifconfig._IfconfigParser.parser"></a>
|
|
|
|
|
|
|
|
#### parser
|
|
|
|
|
|
|
|
```python
|
|
|
|
def parser(source_data)
|
|
|
|
```
|
|
|
|
|
|
|
|
**Arguments**:
|
|
|
|
|
|
|
|
- `source_data`:
|
|
|
|
|
|
|
|
<a id="jc.parsers.ifconfig.parse"></a>
|
|
|
|
|
|
|
|
#### parse
|
|
|
|
|
2019-11-11 18:30:46 -08:00
|
|
|
```python
|
2022-01-25 17:07:47 -08:00
|
|
|
def parse(data, raw=False, quiet=False)
|
2019-11-11 18:30:46 -08:00
|
|
|
```
|
|
|
|
|
2019-11-12 11:18:00 -08:00
|
|
|
Main text parsing function
|
2019-11-11 18:30:46 -08:00
|
|
|
|
2022-01-25 17:07:47 -08:00
|
|
|
**Arguments**:
|
2019-11-11 18:30:46 -08:00
|
|
|
|
2022-01-25 17:07:47 -08:00
|
|
|
|
|
|
|
- `data` - (string) text data to parse
|
|
|
|
- `raw` - (boolean) unprocessed output if True
|
|
|
|
- `quiet` - (boolean) suppress warning messages if True
|
|
|
|
|
2019-11-12 11:18:00 -08:00
|
|
|
|
2022-01-25 17:07:47 -08:00
|
|
|
**Returns**:
|
2019-11-12 11:18:00 -08:00
|
|
|
|
2022-01-25 17:07:47 -08:00
|
|
|
|
|
|
|
List of Dictionaries. Raw or processed structured data.
|
2019-11-11 18:30:46 -08:00
|
|
|
|
2021-04-09 10:36:42 -07:00
|
|
|
## Parser Information
|
|
|
|
Compatibility: linux, aix, freebsd, darwin
|
|
|
|
|
2021-12-01 16:12:51 -08:00
|
|
|
Version 1.11 by Kelly Brazil (kellyjonbrazil@gmail.com)
|