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
|
|
|
|
2022-12-02 16:10:00 -08:00
|
|
|
jc - JSON Convert `ifconfig` command output parser
|
2020-08-05 16:51:58 -07:00
|
|
|
|
2022-11-04 09:25:17 -07:00
|
|
|
No `ifconfig` options are supported.
|
|
|
|
|
|
|
|
Consider using the `ip` command instead of `ifconfig` as it supports native
|
2022-11-05 16:36:31 -07:00
|
|
|
JSON output.
|
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 18:03:34 -08:00
|
|
|
$ ifconfig | jc --ifconfig
|
2020-08-05 16:51:58 -07:00
|
|
|
|
2022-08-15 13:51:48 -07:00
|
|
|
or
|
2019-11-11 18:30:46 -08:00
|
|
|
|
2022-01-25 18:03:34 -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 18:03:34 -08:00
|
|
|
import jc
|
|
|
|
result = jc.parse('ifconfig', ifconfig_command_output)
|
2022-01-18 15:38:03 -08:00
|
|
|
|
2021-04-08 12:42:01 -07:00
|
|
|
Schema:
|
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
[
|
|
|
|
{
|
2022-11-06 12:04:34 -08:00
|
|
|
"name": string,
|
|
|
|
"type": string,
|
|
|
|
"metric": integer
|
|
|
|
"flags": integer,
|
2022-01-25 18:03:34 -08:00
|
|
|
"state": [
|
2022-11-06 12:04:34 -08:00
|
|
|
string
|
2022-01-25 18:03:34 -08:00
|
|
|
],
|
2022-11-06 12:04:34 -08:00
|
|
|
"mtu": integer,
|
|
|
|
"mac_addr": string,
|
|
|
|
"ipv4_addr": string, # [0]
|
|
|
|
"ipv4_mask": string, # [0]
|
|
|
|
"ipv4_bcast": string, # [0]
|
|
|
|
"ipv6_addr": string, # [0]
|
|
|
|
"ipv6_mask": integer, # [0]
|
|
|
|
"ipv6_scope": string, # [0]
|
2022-12-02 15:16:46 -08:00
|
|
|
"ipv6_scope_id": string, # [0]
|
2022-11-06 12:04:34 -08:00
|
|
|
"ipv6_type": string, # [0]
|
|
|
|
"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,
|
2022-11-07 10:44:37 -08:00
|
|
|
"options": string,
|
|
|
|
"options_flags": [
|
|
|
|
string
|
|
|
|
],
|
2022-11-06 12:04:34 -08:00
|
|
|
"status": string,
|
|
|
|
"hw_address": string,
|
|
|
|
"media": string,
|
|
|
|
"media_flags": [
|
|
|
|
string
|
|
|
|
],
|
|
|
|
"nd6_options": integer,
|
|
|
|
"nd6_flags": [
|
|
|
|
string
|
|
|
|
],
|
|
|
|
"plugged": string,
|
|
|
|
"vendor": string,
|
|
|
|
"vendor_pn": string,
|
|
|
|
"vendor_sn": string,
|
|
|
|
"vendor_date": string,
|
|
|
|
"module_temperature": string,
|
|
|
|
"module_voltage": string
|
2022-11-05 16:36:31 -07:00
|
|
|
"ipv4": [
|
|
|
|
{
|
2022-11-06 12:04:34 -08:00
|
|
|
"address": string,
|
|
|
|
"mask": string,
|
|
|
|
"broadcast": string
|
2022-11-05 16:36:31 -07:00
|
|
|
}
|
|
|
|
],
|
|
|
|
"ipv6: [
|
|
|
|
{
|
2022-11-06 12:04:34 -08:00
|
|
|
"address": string,
|
2022-12-02 15:16:46 -08:00
|
|
|
"scope_id": string,
|
2022-11-06 12:04:34 -08:00
|
|
|
"mask": integer,
|
|
|
|
"scope": string,
|
|
|
|
"type": string
|
2022-11-05 16:36:31 -07:00
|
|
|
}
|
2022-12-02 15:16:46 -08:00
|
|
|
],
|
|
|
|
"lanes": [
|
|
|
|
{
|
|
|
|
"lane": integer,
|
|
|
|
"rx_power_mw": float,
|
|
|
|
"rx_power_dbm": float,
|
|
|
|
"tx_bias_ma": float
|
|
|
|
}
|
2022-11-05 16:36:31 -07:00
|
|
|
]
|
2022-01-25 18:03:34 -08:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2022-11-05 16:36:31 -07:00
|
|
|
[0] these fields only pick up the last IP address in the interface
|
|
|
|
output and are here for backwards compatibility. For information on
|
|
|
|
all IP addresses, use the `ipv4` and `ipv6` objects which contain an
|
|
|
|
array of IP address objects.
|
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
Examples:
|
|
|
|
|
2022-11-05 16:36:31 -07:00
|
|
|
$ ifconfig ens33 | jc --ifconfig -p
|
2022-01-25 18:03:34 -08:00
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "ens33",
|
|
|
|
"flags": 4163,
|
|
|
|
"state": [
|
|
|
|
"UP",
|
|
|
|
"BROADCAST",
|
|
|
|
"RUNNING",
|
|
|
|
"MULTICAST"
|
|
|
|
],
|
|
|
|
"mtu": 1500,
|
2022-11-05 16:36:31 -07:00
|
|
|
"type": "Ethernet",
|
|
|
|
"mac_addr": "00:0c:29:3b:58:0e",
|
2022-01-25 18:03:34 -08:00
|
|
|
"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",
|
2022-11-05 16:36:31 -07:00
|
|
|
"ipv6_type": "link",
|
|
|
|
"metric": null,
|
2022-01-25 18:03:34 -08:00
|
|
|
"rx_packets": 8061,
|
|
|
|
"rx_errors": 0,
|
|
|
|
"rx_dropped": 0,
|
|
|
|
"rx_overruns": 0,
|
|
|
|
"rx_frame": 0,
|
|
|
|
"tx_packets": 4502,
|
|
|
|
"tx_errors": 0,
|
|
|
|
"tx_dropped": 0,
|
|
|
|
"tx_overruns": 0,
|
|
|
|
"tx_carrier": 0,
|
|
|
|
"tx_collisions": 0,
|
2022-11-05 16:36:31 -07:00
|
|
|
"rx_bytes": 1514413,
|
|
|
|
"tx_bytes": 866622,
|
|
|
|
"ipv4": [
|
|
|
|
{
|
|
|
|
"address": "192.168.71.137",
|
|
|
|
"mask": "255.255.255.0",
|
|
|
|
"broadcast": "192.168.71.255"
|
|
|
|
}
|
2022-01-25 18:03:34 -08:00
|
|
|
],
|
2022-11-05 16:36:31 -07:00
|
|
|
"ipv6": [
|
|
|
|
{
|
|
|
|
"address": "fe80::c1cb:715d:bc3e:b8a0",
|
2022-12-02 15:16:46 -08:00
|
|
|
"scope_id": null,
|
2022-11-05 16:36:31 -07:00
|
|
|
"mask": 64,
|
|
|
|
"scope": "0x20",
|
|
|
|
"type": "link"
|
|
|
|
}
|
|
|
|
]
|
2022-01-25 18:03:34 -08:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2022-11-05 16:36:31 -07:00
|
|
|
$ ifconfig ens33 | jc --ifconfig -p -r
|
2022-01-25 18:03:34 -08:00
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "ens33",
|
|
|
|
"flags": "4163",
|
|
|
|
"state": "UP,BROADCAST,RUNNING,MULTICAST",
|
|
|
|
"mtu": "1500",
|
2022-11-05 16:36:31 -07:00
|
|
|
"type": "Ethernet",
|
|
|
|
"mac_addr": "00:0c:29:3b:58:0e",
|
2022-01-25 18:03:34 -08:00
|
|
|
"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",
|
2022-11-05 16:36:31 -07:00
|
|
|
"ipv6_type": "link",
|
|
|
|
"metric": null,
|
2022-01-25 18:03:34 -08:00
|
|
|
"rx_packets": "8061",
|
|
|
|
"rx_errors": "0",
|
|
|
|
"rx_dropped": "0",
|
|
|
|
"rx_overruns": "0",
|
|
|
|
"rx_frame": "0",
|
|
|
|
"tx_packets": "4502",
|
|
|
|
"tx_errors": "0",
|
|
|
|
"tx_dropped": "0",
|
|
|
|
"tx_overruns": "0",
|
|
|
|
"tx_carrier": "0",
|
|
|
|
"tx_collisions": "0",
|
2022-11-05 16:36:31 -07:00
|
|
|
"rx_bytes": "1514413",
|
|
|
|
"tx_bytes": "866622",
|
|
|
|
"ipv4": [
|
|
|
|
{
|
|
|
|
"address": "192.168.71.137",
|
|
|
|
"mask": "255.255.255.0",
|
|
|
|
"broadcast": "192.168.71.255"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"ipv6": [
|
|
|
|
{
|
|
|
|
"address": "fe80::c1cb:715d:bc3e:b8a0",
|
2022-12-02 15:16:46 -08:00
|
|
|
"scope_id": null,
|
2022-11-05 16:36:31 -07:00
|
|
|
"mask": "64",
|
|
|
|
"scope": "0x20",
|
|
|
|
"type": "link"
|
|
|
|
}
|
|
|
|
]
|
2022-01-25 18:03:34 -08:00
|
|
|
}
|
|
|
|
]
|
2022-01-25 17:07:47 -08:00
|
|
|
|
|
|
|
<a id="jc.parsers.ifconfig.parse"></a>
|
|
|
|
|
2022-03-05 12:15:14 -08:00
|
|
|
### parse
|
2022-01-25 17:07:47 -08:00
|
|
|
|
2019-11-11 18:30:46 -08:00
|
|
|
```python
|
2022-11-05 16:36:31 -07:00
|
|
|
def parse(data: str,
|
|
|
|
raw: bool = False,
|
2024-03-14 22:46:52 -07:00
|
|
|
quiet: bool = False) -> List[Dict[str, Any]]
|
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 18:03:34 -08:00
|
|
|
Parameters:
|
2019-11-11 18:30:46 -08:00
|
|
|
|
2022-01-25 18:03:34 -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 18:03:34 -08:00
|
|
|
Returns:
|
2019-11-12 11:18:00 -08:00
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
List of Dictionaries. Raw or processed structured data.
|
2019-11-11 18:30:46 -08:00
|
|
|
|
2022-01-25 19:18:54 -08:00
|
|
|
### Parser Information
|
2021-04-09 10:36:42 -07:00
|
|
|
Compatibility: linux, aix, freebsd, darwin
|
|
|
|
|
2023-12-21 14:55:21 -08:00
|
|
|
Source: [`jc/parsers/ifconfig.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/ifconfig.py)
|
|
|
|
|
2024-09-07 19:50:08 -07:00
|
|
|
Version 2.4 by Kelly Brazil (kellyjonbrazil@gmail.com)
|