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.ss"></a>
|
2020-07-30 16:20:24 -07:00
|
|
|
|
2019-11-14 17:23:44 -08:00
|
|
|
# jc.parsers.ss
|
2022-01-25 17:07:47 -08:00
|
|
|
|
2022-03-04 13:27:39 -08:00
|
|
|
jc - JSON Convert `ss` command output parser
|
2019-11-13 07:45:37 -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
|
|
|
$ ss | jc --ss
|
2020-08-05 16:51:58 -07:00
|
|
|
|
2022-08-15 13:51:48 -07:00
|
|
|
or
|
2020-08-05 16:51:58 -07:00
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
$ jc ss
|
2019-11-14 17:23:44 -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('ss', ss_command_output)
|
2022-01-18 15:38:03 -08:00
|
|
|
|
2021-04-08 15:52:49 -07:00
|
|
|
Schema:
|
|
|
|
|
2022-05-26 15:54:39 -07:00
|
|
|
Information from https://www.cyberciti.biz/files/ss.html used to define
|
|
|
|
field names
|
2019-12-12 09:47:14 -08:00
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
[
|
|
|
|
{
|
2023-06-22 01:48:23 +03:00
|
|
|
"netid": string,
|
|
|
|
"state": string,
|
|
|
|
"recv_q": integer,
|
|
|
|
"send_q": integer,
|
|
|
|
"local_address": string,
|
|
|
|
"local_port": string,
|
|
|
|
"local_port_num": integer,
|
|
|
|
"peer_address": string,
|
|
|
|
"peer_port": string,
|
|
|
|
"peer_port_num": integer,
|
|
|
|
"interface": string,
|
|
|
|
"link_layer" string,
|
|
|
|
"channel": string,
|
|
|
|
"path": string,
|
|
|
|
"pid": integer,
|
|
|
|
"opts": {
|
|
|
|
"process_id": {
|
|
|
|
"<process_id>": {
|
|
|
|
"user": string,
|
|
|
|
"file_descriptor": string
|
|
|
|
}
|
|
|
|
}
|
2024-06-07 17:42:30 -07:00
|
|
|
"inode_number": string,
|
|
|
|
"cookie": string,
|
|
|
|
"cgroup": string,
|
|
|
|
"v6only": string,
|
|
|
|
"timer_name": string,
|
|
|
|
"expire_time": string,
|
|
|
|
"retrans": string
|
2023-06-22 01:48:23 +03:00
|
|
|
}
|
2022-01-25 18:03:34 -08:00
|
|
|
}
|
|
|
|
]
|
2019-11-14 13:37:55 -08:00
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
Examples:
|
2019-11-13 07:45:37 -08:00
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
$ sudo ss -a | jc --ss -p
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"netid": "nl",
|
|
|
|
"state": "UNCONN",
|
|
|
|
"recv_q": 0,
|
|
|
|
"send_q": 0,
|
|
|
|
"peer_address": "*",
|
|
|
|
"channel": "rtnl:kernel"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"netid": "nl",
|
|
|
|
"state": "UNCONN",
|
|
|
|
"recv_q": 0,
|
|
|
|
"send_q": 0,
|
|
|
|
"peer_address": "*",
|
|
|
|
"pid": 893,
|
|
|
|
"channel": "rtnl:systemd-resolve"
|
|
|
|
},
|
|
|
|
...
|
|
|
|
{
|
|
|
|
"netid": "p_raw",
|
|
|
|
"state": "UNCONN",
|
|
|
|
"recv_q": 0,
|
|
|
|
"send_q": 0,
|
|
|
|
"peer_address": "*",
|
|
|
|
"link_layer": "LLDP",
|
|
|
|
"interface": "ens33"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"netid": "u_dgr",
|
|
|
|
"state": "UNCONN",
|
|
|
|
"recv_q": 0,
|
|
|
|
"send_q": 0,
|
|
|
|
"local_port": "93066",
|
|
|
|
"peer_address": "*",
|
|
|
|
"peer_port": "0",
|
|
|
|
"path": "/run/user/1000/systemd/notify"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"netid": "u_seq",
|
|
|
|
"state": "LISTEN",
|
|
|
|
"recv_q": 0,
|
|
|
|
"send_q": 128,
|
|
|
|
"local_port": "20699",
|
|
|
|
"peer_address": "*",
|
|
|
|
"peer_port": "0",
|
|
|
|
"path": "/run/udev/control"
|
|
|
|
},
|
|
|
|
...
|
|
|
|
{
|
|
|
|
"netid": "icmp6",
|
|
|
|
"state": "UNCONN",
|
|
|
|
"recv_q": 0,
|
|
|
|
"send_q": 0,
|
|
|
|
"local_address": "*",
|
|
|
|
"local_port": "ipv6-icmp",
|
|
|
|
"peer_address": "*",
|
|
|
|
"peer_port": "*",
|
|
|
|
"interface": "ens33"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"netid": "udp",
|
|
|
|
"state": "UNCONN",
|
|
|
|
"recv_q": 0,
|
|
|
|
"send_q": 0,
|
|
|
|
"local_address": "127.0.0.53",
|
|
|
|
"local_port": "domain",
|
|
|
|
"peer_address": "0.0.0.0",
|
|
|
|
"peer_port": "*",
|
|
|
|
"interface": "lo"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"netid": "tcp",
|
|
|
|
"state": "LISTEN",
|
|
|
|
"recv_q": 0,
|
|
|
|
"send_q": 128,
|
|
|
|
"local_address": "127.0.0.53",
|
|
|
|
"local_port": "domain",
|
|
|
|
"peer_address": "0.0.0.0",
|
|
|
|
"peer_port": "*",
|
|
|
|
"interface": "lo"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"netid": "tcp",
|
|
|
|
"state": "LISTEN",
|
|
|
|
"recv_q": 0,
|
|
|
|
"send_q": 128,
|
|
|
|
"local_address": "0.0.0.0",
|
|
|
|
"local_port": "ssh",
|
|
|
|
"peer_address": "0.0.0.0",
|
|
|
|
"peer_port": "*"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"netid": "tcp",
|
|
|
|
"state": "LISTEN",
|
|
|
|
"recv_q": 0,
|
|
|
|
"send_q": 128,
|
|
|
|
"local_address": "[::]",
|
|
|
|
"local_port": "ssh",
|
|
|
|
"peer_address": "[::]",
|
|
|
|
"peer_port": "*"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"netid": "v_str",
|
|
|
|
"state": "ESTAB",
|
|
|
|
"recv_q": 0,
|
|
|
|
"send_q": 0,
|
|
|
|
"local_address": "999900439",
|
|
|
|
"local_port": "1023",
|
|
|
|
"peer_address": "0",
|
|
|
|
"peer_port": "976",
|
|
|
|
"local_port_num": 1023,
|
|
|
|
"peer_port_num": 976
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
$ sudo ss -a | jc --ss -p -r
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"netid": "nl",
|
|
|
|
"state": "UNCONN",
|
|
|
|
"recv_q": "0",
|
|
|
|
"send_q": "0",
|
|
|
|
"peer_address": "*",
|
|
|
|
"channel": "rtnl:kernel"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"netid": "nl",
|
|
|
|
"state": "UNCONN",
|
|
|
|
"recv_q": "0",
|
|
|
|
"send_q": "0",
|
|
|
|
"peer_address": "*",
|
|
|
|
"pid": "893",
|
|
|
|
"channel": "rtnl:systemd-resolve"
|
|
|
|
},
|
|
|
|
...
|
|
|
|
{
|
|
|
|
"netid": "p_raw",
|
|
|
|
"state": "UNCONN",
|
|
|
|
"recv_q": "0",
|
|
|
|
"send_q": "0",
|
|
|
|
"peer_address": "*",
|
|
|
|
"link_layer": "LLDP",
|
|
|
|
"interface": "ens33"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"netid": "u_dgr",
|
|
|
|
"state": "UNCONN",
|
|
|
|
"recv_q": "0",
|
|
|
|
"send_q": "0",
|
|
|
|
"local_port": "93066",
|
|
|
|
"peer_address": "*",
|
|
|
|
"peer_port": "0",
|
|
|
|
"path": "/run/user/1000/systemd/notify"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"netid": "u_seq",
|
|
|
|
"state": "LISTEN",
|
|
|
|
"recv_q": "0",
|
|
|
|
"send_q": "128",
|
|
|
|
"local_port": "20699",
|
|
|
|
"peer_address": "*",
|
|
|
|
"peer_port": "0",
|
|
|
|
"path": "/run/udev/control"
|
|
|
|
},
|
|
|
|
...
|
|
|
|
{
|
|
|
|
"netid": "icmp6",
|
|
|
|
"state": "UNCONN",
|
|
|
|
"recv_q": "0",
|
|
|
|
"send_q": "0",
|
|
|
|
"local_address": "*",
|
|
|
|
"local_port": "ipv6-icmp",
|
|
|
|
"peer_address": "*",
|
|
|
|
"peer_port": "*",
|
|
|
|
"interface": "ens33"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"netid": "udp",
|
|
|
|
"state": "UNCONN",
|
|
|
|
"recv_q": "0",
|
|
|
|
"send_q": "0",
|
|
|
|
"local_address": "127.0.0.53",
|
|
|
|
"local_port": "domain",
|
|
|
|
"peer_address": "0.0.0.0",
|
|
|
|
"peer_port": "*",
|
|
|
|
"interface": "lo"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"netid": "tcp",
|
|
|
|
"state": "LISTEN",
|
|
|
|
"recv_q": "0",
|
|
|
|
"send_q": "128",
|
|
|
|
"local_address": "127.0.0.53",
|
|
|
|
"local_port": "domain",
|
|
|
|
"peer_address": "0.0.0.0",
|
|
|
|
"peer_port": "*",
|
|
|
|
"interface": "lo"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"netid": "tcp",
|
|
|
|
"state": "LISTEN",
|
|
|
|
"recv_q": "0",
|
|
|
|
"send_q": "128",
|
|
|
|
"local_address": "0.0.0.0",
|
|
|
|
"local_port": "ssh",
|
|
|
|
"peer_address": "0.0.0.0",
|
|
|
|
"peer_port": "*"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"netid": "tcp",
|
|
|
|
"state": "LISTEN",
|
|
|
|
"recv_q": "0",
|
|
|
|
"send_q": "128",
|
|
|
|
"local_address": "[::]",
|
|
|
|
"local_port": "ssh",
|
|
|
|
"peer_address": "[::]",
|
|
|
|
"peer_port": "*"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"netid": "v_str",
|
|
|
|
"state": "ESTAB",
|
|
|
|
"recv_q": "0",
|
|
|
|
"send_q": "0",
|
|
|
|
"local_address": "999900439",
|
|
|
|
"local_port": "1023",
|
|
|
|
"peer_address": "0",
|
|
|
|
"peer_port": "976"
|
|
|
|
}
|
|
|
|
]
|
2019-11-13 07:45:37 -08:00
|
|
|
|
2022-01-25 17:07:47 -08:00
|
|
|
<a id="jc.parsers.ss.parse"></a>
|
|
|
|
|
2022-03-05 12:15:14 -08:00
|
|
|
### parse
|
2022-01-25 17:07:47 -08:00
|
|
|
|
2019-11-13 07:45:37 -08:00
|
|
|
```python
|
2022-01-25 17:07:47 -08:00
|
|
|
def parse(data, raw=False, quiet=False)
|
2019-11-13 07:45:37 -08:00
|
|
|
```
|
|
|
|
|
|
|
|
Main text parsing function
|
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
Parameters:
|
2019-11-13 07:45:37 -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-13 07:45:37 -08:00
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
Returns:
|
2019-11-13 07:45:37 -08:00
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
List of Dictionaries. Raw or processed structured data.
|
2019-11-13 07:45:37 -08:00
|
|
|
|
2022-01-25 19:18:54 -08:00
|
|
|
### Parser Information
|
2021-04-09 10:36:42 -07:00
|
|
|
Compatibility: linux
|
|
|
|
|
2023-12-21 14:55:21 -08:00
|
|
|
Source: [`jc/parsers/ss.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/ss.py)
|
|
|
|
|
2024-06-07 17:42:30 -07:00
|
|
|
Version 1.8 by Kelly Brazil (kellyjonbrazil@gmail.com)
|