1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-17 00:07:37 +02:00
Files
jc/docs/parsers/ufw.md

316 lines
9.2 KiB
Markdown
Raw Normal View History

2021-04-21 07:51:32 -07:00
[Home](https://kellyjonbrazil.github.io/jc/)
# jc.parsers.ufw
jc - JSON CLI output utility `ufw status` command output parser
Note: a list of ports will be parsed to the `to_service` or `from_service` field as a comma-separated string.
2021-04-21 07:51:32 -07:00
Usage (cli):
$ ufw status | jc --ufw
or
$ jc ufw status
Usage (module):
import jc.parsers.ufw
result = jc.parsers.ufw.parse(ufw_command_output)
Schema:
{
"status": string,
"logging": string,
"logging_level": string,
"default": string,
"new_profiles": string,
"rules": [
{
"action": string,
"action_direction": string, # null if blank
"index": integer, # null if blank
"network_protocol": string,
"to_ip": string,
"to_ip_prefix": integer,
"to_interface": string,
"to_transport": string, # null if to_service is set and not a list of ports
"to_start_port": integer, # null if to_service is set and not a list of ports
"to_end_port": integer, # null if to_service is set and not a list of ports
"to_service": string, # null if any above are set (can also be a list of ports)
2021-04-21 07:51:32 -07:00
"from_ip": string,
"from_ip_prefix": integer,
"from_interface": string,
"from_transport": string, # null if to_service is set and not a list of ports
"from_start_port": integer, # null if to_service is set and not a list of ports
"from_end_port": integer, # null if to_service is set and not a list of ports
"from_service": string, # null if any above are set (can also be a list of ports)
"comment": string # null if no comment
2021-04-21 07:51:32 -07:00
}
]
}
Examples:
2021-04-23 16:14:53 -07:00
$ ufw status verbose | jc --ufw -p
2021-04-21 07:51:32 -07:00
{
"status": "active",
"logging": "on",
"logging_level": "low",
"default": "deny (incoming), allow (outgoing), deny (routed)",
"new_profiles": "skip",
"rules": [
{
"action": "ALLOW",
"action_direction": "IN",
2021-04-23 16:14:53 -07:00
"index": null,
2021-04-21 07:51:32 -07:00
"network_protocol": "ipv4",
"to_interface": "any",
"to_transport": "tcp",
"to_start_port": 22,
"to_end_port": 22,
"to_service": null,
"to_ip": "0.0.0.0",
"to_ip_prefix": 0,
"comment": null,
2021-04-21 07:51:32 -07:00
"from_ip": "0.0.0.0",
"from_ip_prefix": 0,
2021-04-21 07:51:32 -07:00
"from_interface": "any",
"from_transport": "any",
"from_start_port": 0,
"from_end_port": 65535,
"from_service": null
},
{
"action": "ALLOW",
"action_direction": "IN",
2021-04-23 16:14:53 -07:00
"index": null,
2021-04-21 07:51:32 -07:00
"network_protocol": "ipv6",
"to_interface": "any",
"to_transport": "tcp",
"to_start_port": 22,
"to_end_port": 22,
"to_service": null,
"to_ip": "::",
"to_ip_prefix": 0,
"comment": null,
2021-04-21 07:51:32 -07:00
"from_ip": "::",
"from_ip_prefix": 0,
2021-04-21 07:51:32 -07:00
"from_interface": "any",
"from_transport": "any",
"from_start_port": 0,
"from_end_port": 65535,
"from_service": null
},
{
"action": "ALLOW",
"action_direction": "IN",
2021-04-23 16:14:53 -07:00
"index": null,
2021-04-21 07:51:32 -07:00
"network_protocol": "ipv4",
"to_interface": "any",
"to_transport": null,
"to_service": "Apache Full",
"to_start_port": null,
"to_end_port": null,
"to_ip": "0.0.0.0",
"to_ip_prefix": 0,
"comment": null,
2021-04-21 07:51:32 -07:00
"from_ip": "0.0.0.0",
"from_ip_prefix": 0,
2021-04-21 07:51:32 -07:00
"from_interface": "any",
"from_transport": "any",
"from_start_port": 0,
"from_end_port": 65535,
"from_service": null
},
{
"action": "ALLOW",
"action_direction": "IN",
2021-04-23 16:14:53 -07:00
"index": null,
2021-04-21 07:51:32 -07:00
"network_protocol": "ipv6",
"to_interface": "any",
"to_ip": "2405:204:7449:49fc:f09a:6f4a:bc93:1955",
"to_ip_prefix": 128,
2021-04-21 07:51:32 -07:00
"to_transport": "any",
"to_start_port": 0,
"to_end_port": 65535,
"to_service": null,
"comment": null,
2021-04-21 07:51:32 -07:00
"from_ip": "::",
"from_ip_prefix": 0,
2021-04-21 07:51:32 -07:00
"from_interface": "any",
"from_transport": "any",
"from_start_port": 0,
"from_end_port": 65535,
"from_service": null
},
{
"action": "ALLOW",
"action_direction": "IN",
2021-04-23 16:14:53 -07:00
"index": null,
2021-04-21 07:51:32 -07:00
"network_protocol": "ipv4",
"to_interface": "en0",
"to_ip": "10.10.10.10",
"to_ip_prefix": 32,
2021-04-21 07:51:32 -07:00
"to_transport": "any",
"to_start_port": 0,
"to_end_port": 65535,
"to_service": null,
"comment": null,
2021-04-21 07:51:32 -07:00
"from_ip": "0.0.0.0",
"from_ip_prefix": 0,
2021-04-21 07:51:32 -07:00
"from_interface": "any",
"from_transport": "any",
"from_start_port": 0,
"from_end_port": 65535,
"from_service": null
}
]
}
2021-04-23 16:14:53 -07:00
$ ufw status verbose | jc --ufw -p -r
2021-04-21 07:51:32 -07:00
{
"status": "active",
"logging": "on",
"logging_level": "low",
"default": "deny (incoming), allow (outgoing), deny (routed)",
"new_profiles": "skip",
"rules": [
{
"action": "ALLOW",
"action_direction": "IN",
2021-04-23 16:14:53 -07:00
"index": null,
2021-04-21 07:51:32 -07:00
"network_protocol": "ipv4",
"to_interface": "any",
"to_transport": "tcp",
"to_start_port": "22",
"to_end_port": "22",
"to_service": null,
"to_ip": "0.0.0.0",
"to_ip_prefix": "0",
"comment": null,
2021-04-21 07:51:32 -07:00
"from_ip": "0.0.0.0",
"from_ip_prefix": "0",
"from_interface": "any",
"from_transport": "any",
"from_start_port": "0",
"from_end_port": "65535",
"from_service": null
},
{
"action": "ALLOW",
"action_direction": "IN",
2021-04-23 16:14:53 -07:00
"index": null,
2021-04-21 07:51:32 -07:00
"network_protocol": "ipv6",
"to_interface": "any",
"to_transport": "tcp",
"to_start_port": "22",
"to_end_port": "22",
"to_service": null,
"to_ip": "::",
"to_ip_prefix": "0",
"comment": null,
2021-04-21 07:51:32 -07:00
"from_ip": "::",
"from_ip_prefix": "0",
"from_interface": "any",
"from_transport": "any",
"from_start_port": "0",
"from_end_port": "65535",
"from_service": null
},
{
"action": "ALLOW",
"action_direction": "IN",
2021-04-23 16:14:53 -07:00
"index": null,
2021-04-21 07:51:32 -07:00
"network_protocol": "ipv4",
"to_interface": "any",
"to_transport": null,
"to_service": "Apache Full",
"to_start_port": null,
"to_end_port": null,
"to_ip": "0.0.0.0",
"to_ip_prefix": "0",
"comment": null,
2021-04-21 07:51:32 -07:00
"from_ip": "0.0.0.0",
"from_ip_prefix": "0",
"from_interface": "any",
"from_transport": "any",
"from_start_port": "0",
"from_end_port": "65535",
"from_service": null
},
{
"action": "ALLOW",
"action_direction": "IN",
2021-04-23 16:14:53 -07:00
"index": null,
2021-04-21 07:51:32 -07:00
"network_protocol": "ipv6",
"to_interface": "any",
"to_ip": "2405:204:7449:49fc:f09a:6f4a:bc93:1955",
"to_ip_prefix": "128",
"to_transport": "any",
"to_start_port": "0",
"to_end_port": "65535",
"to_service": null,
"comment": null,
2021-04-21 07:51:32 -07:00
"from_ip": "::",
"from_ip_prefix": "0",
"from_interface": "any",
"from_transport": "any",
"from_start_port": "0",
"from_end_port": "65535",
"from_service": null
},
{
"action": "ALLOW",
"action_direction": "IN",
2021-04-23 16:14:53 -07:00
"index": null,
2021-04-21 07:51:32 -07:00
"network_protocol": "ipv4",
"to_interface": "en0",
"to_ip": "10.10.10.10",
"to_ip_prefix": "32",
"to_transport": "any",
"to_start_port": "0",
"to_end_port": "65535",
"to_service": null,
"comment": null,
2021-04-21 07:51:32 -07:00
"from_ip": "0.0.0.0",
"from_ip_prefix": "0",
"from_interface": "any",
"from_transport": "any",
"from_start_port": "0",
"from_end_port": "65535",
"from_service": null
}
]
}
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
## parse
```python
parse(data, raw=False, quiet=False)
```
Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
quiet: (boolean) suppress warning messages if True
Returns:
Dictionary. Raw or processed structured data.
## Parser Information
Compatibility: linux
Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)