1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2026-04-03 17:44:07 +02:00

Compare commits

...

166 Commits

Author SHA1 Message Date
Kelly Brazil
2af61730f0 Merge pull request #68 from kellyjonbrazil/dev
Dev v1.11.5
2020-06-12 12:34:34 -07:00
Kelly Brazil
83f41b83dc version bump 2020-06-12 12:30:19 -07:00
Kelly Brazil
1fb84fce88 fix for no data 2020-06-12 12:25:07 -07:00
Kelly Brazil
a8837e1244 remove --upgrade from pip install 2020-06-12 07:57:40 -07:00
Kelly Brazil
04d2eec558 fix for no data 2020-06-11 17:59:06 -07:00
Kelly Brazil
1b57ec92f0 fix for no data 2020-06-11 17:52:03 -07:00
Kelly Brazil
4d88595404 enhance empty data check 2020-06-11 17:16:11 -07:00
Kelly Brazil
52b1272a3a enhance empty data check 2020-06-11 17:13:45 -07:00
Kelly Brazil
d2ccad6a83 fix for no data 2020-06-11 17:09:51 -07:00
Kelly Brazil
cad6dde4ac fix for no data 2020-06-10 17:54:06 -07:00
Kelly Brazil
06811c3539 add test for no data 2020-06-10 17:41:54 -07:00
Kelly Brazil
0cb23c2b21 add fix for no data 2020-06-10 17:40:18 -07:00
Kelly Brazil
ac4688dca2 add test for no data 2020-06-10 17:35:40 -07:00
Kelly Brazil
326c3b4670 add test for no data 2020-06-10 17:34:22 -07:00
Kelly Brazil
9b29d0c268 add test for no data 2020-06-10 17:32:39 -07:00
Kelly Brazil
e0013c3871 add test for no data 2020-06-10 17:31:14 -07:00
Kelly Brazil
a75744075b add no data test 2020-06-10 17:29:41 -07:00
Kelly Brazil
525aec1a02 fix for no data 2020-06-10 17:27:46 -07:00
Kelly Brazil
0bf9a7a072 add test for no data 2020-06-10 17:22:59 -07:00
Kelly Brazil
d8f2f4c95b fix for no data 2020-06-10 17:20:09 -07:00
Kelly Brazil
35d733b44f fix for no data 2020-06-10 17:10:53 -07:00
Kelly Brazil
9179b4175c add nodata tests 2020-06-10 16:40:11 -07:00
Kelly Brazil
bb07d78c78 add nodata fix 2020-06-10 16:39:49 -07:00
Kelly Brazil
07b179cd7f Merge pull request #67 from kellyjonbrazil/Dev
Dev v1.11.4
2020-06-10 06:07:42 -07:00
Kelly Brazil
054422d837 add test for empty directory 2020-06-10 06:04:50 -07:00
Kelly Brazil
3e052d1810 version bump 2020-06-10 05:53:20 -07:00
Kelly Brazil
c8e72805cf fix error on empty directory 2020-06-10 05:51:12 -07:00
Kelly Brazil
12a80e7db0 add fedora package info 2020-06-09 15:13:53 -07:00
Kelly Brazil
ee7ff9a09d Merge pull request #66 from kellyjonbrazil/dev
Dev v1.11.3
2020-06-09 11:22:39 -07:00
Kelly Brazil
f6478fb636 version bump 2020-06-09 11:18:47 -07:00
Kelly Brazil
811a0b0495 add info regarding the local parser plugin files 2020-06-08 10:54:42 -07:00
Kelly Brazil
aeb48edf72 use $LOCALAPPDATA variable for windows 2020-06-08 10:48:58 -07:00
Kelly Brazil
b1e94f0df7 heading formatting 2020-06-08 10:44:09 -07:00
Kelly Brazil
60050e3c0f fix linux/unix directory and add note about the XDG specification followed 2020-06-08 10:42:45 -07:00
Kelly Brazil
39ef09aa5b add local parser plugin feature 2020-06-07 13:30:22 -07:00
Kelly Brazil
8377d43116 formatting 2020-06-07 13:26:03 -07:00
Kelly Brazil
54e4c447ab clean up formatting 2020-06-07 12:52:16 -07:00
Kelly Brazil
937a9fa9cf vendorize appdirs module 2020-06-07 12:41:50 -07:00
Kelly Brazil
808ff6cf0e more acknowledgments updates 2020-06-07 12:29:10 -07:00
Kelly Brazil
7f5c649a95 update acknowledgments 2020-06-07 12:23:28 -07:00
Kelly Brazil
b72727dec9 update custom parsers info 2020-06-07 12:13:40 -07:00
Kelly Brazil
3fc88bfb33 Merge pull request #65 from duelafn/local-parsers
Load custom parsers from <user_data_dir>/jc/jcparsers
2020-06-07 12:04:44 -07:00
Dean Serenevy
9f2279d586 Load custom parsers from <user_data_dir>/jc/jcparsers 2020-06-06 14:42:27 -04:00
Kelly Brazil
346a14cb9b change osx_device to unix_device 2020-05-30 20:44:14 -07:00
Kelly Brazil
dac00d17ff add nixos test 2020-05-30 20:33:50 -07:00
Kelly Brazil
9ca7cd4060 update docs 2020-05-30 20:33:39 -07:00
Kelly Brazil
aa31628970 update docs 2020-05-30 20:33:00 -07:00
Kelly Brazil
bed694fcf5 version bump 2020-05-30 20:13:21 -07:00
Kelly Brazil
4b4af69fa1 fix date 2020-05-30 20:12:51 -07:00
Kelly Brazil
9d96190a5b Merge pull request #64 from kellyjonbrazil/dev
Dev v1.11.2
2020-05-30 20:08:32 -07:00
Kelly Brazil
fa44d48c09 freebsd fixes, tests, and fixtures 2020-05-30 19:50:38 -07:00
Kelly Brazil
4ef961c278 add freebsd test and fixtures 2020-05-30 19:18:01 -07:00
Kelly Brazil
292a837d5c add tests and fixtures for freebsd12 2020-05-30 18:54:09 -07:00
Kelly Brazil
aa7b915d84 version bump 2020-05-30 18:53:46 -07:00
Kelly Brazil
c46fe73236 add last fixes for freebsd 2020-05-30 18:53:35 -07:00
Kelly Brazil
039b2c129c freebsd fixes 2020-05-30 18:42:26 -07:00
Kelly Brazil
8f2e5e4808 fix compatible logic 2020-05-30 17:46:09 -07:00
Kelly Brazil
c4da8e4f78 add nixos and freebsd to tested. update new arp fields 2020-05-30 17:05:41 -07:00
Kelly Brazil
bcab9078a4 add w parser fix 2020-05-30 17:02:09 -07:00
Kelly Brazil
b3c6c1ea92 strip whitespace in string fields and add tests 2020-05-30 17:01:59 -07:00
Kelly Brazil
a3af8662bd add permanent field 2020-05-30 16:26:07 -07:00
Kelly Brazil
35940d0bc8 add freebsd permanent and expires fields 2020-05-30 16:25:53 -07:00
Kelly Brazil
26994cdcb7 add freebsd compatibility info 2020-05-30 15:51:54 -07:00
Kelly Brazil
017159a829 add freebsd nestat tests and fixtures 2020-05-30 15:51:06 -07:00
Kelly Brazil
b4e9c85e08 fixup -T freebsd output and add whitespace stripping to parse_post 2020-05-30 15:50:45 -07:00
Kelly Brazil
189146cd84 add more ints. remove whitespace strip code and move to freebsd_osx module 2020-05-30 15:50:07 -07:00
Kelly Brazil
af34153ffa version bump 2020-05-30 15:48:56 -07:00
Kelly Brazil
bf2ff3ffbb fix compatibility search for platform names that append the version number (e.g. freebsd12) 2020-05-30 15:48:29 -07:00
Kelly Brazil
6423c9efd6 integer and float updates 2020-05-29 15:48:51 -07:00
Kelly Brazil
58ab0d4ece strip whitespace from string fields 2020-05-29 15:14:44 -07:00
Kelly Brazil
83a738bf4d update fixtures for osx_flags and osx_inode name change to unix_flags and unix_inode 2020-05-29 14:16:11 -07:00
Kelly Brazil
3640671fc6 rename module 2020-05-29 14:15:28 -07:00
Kelly Brazil
1da623b30e add items 2020-05-29 14:14:48 -07:00
Kelly Brazil
b10ca64646 change osx_inode and osx_flags to unix_inode and unix_flags. Also rename netstat_osx module to netstat_freebsd_osx 2020-05-29 14:14:37 -07:00
Kelly Brazil
2128763ee6 fix osx version from 16.4 to 14.6 2020-05-29 13:25:19 -07:00
Kelly Brazil
a27e7ed39c test updates for added route_flags_pretty and flags_pretty fields 2020-05-29 13:24:52 -07:00
Kelly Brazil
f07b7eaa47 add flags_pretty 2020-05-29 12:55:16 -07:00
Kelly Brazil
6ce18de84c add route_flags_pretty 2020-05-29 12:51:04 -07:00
Kelly Brazil
8631b756e7 add freebsd test files 2020-05-29 12:05:46 -07:00
Kelly Brazil
7414d98412 add freebsd compatibility 2020-05-29 12:05:34 -07:00
Kelly Brazil
d7b19892e8 add freebsd support for netstat -i 2020-05-29 12:04:58 -07:00
Kelly Brazil
96df396eaf formatting 2020-05-29 07:35:25 -07:00
Kelly Brazil
2f6f640317 spelling 2020-05-27 17:11:20 -07:00
Kelly Brazil
c4a0a50f3a add nix-env 2020-05-27 17:08:54 -07:00
Kelly Brazil
658f8a3842 add zypper and ports info 2020-05-27 14:58:16 -07:00
Kelly Brazil
bfb876a1e3 formatting 2020-05-27 09:52:13 -07:00
Kelly Brazil
90c34b1f4e fix dmidecode example 2020-05-26 17:31:56 -07:00
Kelly Brazil
3f9164ea77 bold formatting 2020-05-23 21:11:17 -07:00
Kelly Brazil
7fd6fecbf5 formatting 2020-05-23 21:09:49 -07:00
Kelly Brazil
8029f72363 change osx_flags from integer to string 2020-05-23 21:09:40 -07:00
Kelly Brazil
c7fdce5d3b Merge pull request #62 from kellyjonbrazil/dev
Dev v1.11.0
2020-05-22 16:37:50 -07:00
Kelly Brazil
84f48aa369 version bump 2020-05-22 16:30:22 -07:00
Kelly Brazil
2e9a0a9c12 add features 2020-05-22 16:21:55 -07:00
Kelly Brazil
c1f6f2b950 osx fixes and tests 2020-05-22 16:21:40 -07:00
Kelly Brazil
ede21bca13 add OSX support for stat 2020-05-22 16:05:04 -07:00
Kelly Brazil
8dd9a9f9cb add netstat -i tests 2020-05-22 15:12:10 -07:00
Kelly Brazil
04f92cd133 add linux support for netstat -i 2020-05-22 14:04:11 -07:00
Kelly Brazil
8be8d2393b add netstat -i support for OSX 2020-05-22 13:38:25 -07:00
Kelly Brazil
0a879681be add netstat -r to docs 2020-05-22 12:56:27 -07:00
Kelly Brazil
2ca1587a49 add linux netstat -r tests 2020-05-22 12:44:51 -07:00
Kelly Brazil
ec2cd2d708 add netstat -r support for linux 2020-05-22 12:00:26 -07:00
Kelly Brazil
5d0dbece93 add netstat -r functionality for OSX 2020-05-22 11:09:41 -07:00
Kelly Brazil
df1e4b414b remove unused folder 2020-05-22 08:00:18 -07:00
Kelly Brazil
40760991e7 update copyright date 2020-05-22 07:51:47 -07:00
Kelly Brazil
464f5f86cf update description 2020-05-22 07:50:22 -07:00
Kelly Brazil
7b09e9fccd set empty values to Null and update fixtures 2020-05-21 17:01:17 -07:00
Kelly Brazil
6cba7d4298 remove linux from description 2020-05-21 11:10:00 -07:00
Kelly Brazil
9730f62e49 fixup name field and update test fixtures 2020-05-21 09:44:28 -07:00
Kelly Brazil
e0c1c87f54 formatting 2020-05-21 09:07:01 -07:00
Kelly Brazil
931b3d2b83 formatting 2020-05-20 19:56:28 -07:00
Kelly Brazil
e5d561baee add multipath condition for osx detection 2020-05-20 17:31:51 -07:00
Kelly Brazil
2867593e7a changelog update 2020-05-20 17:28:44 -07:00
Kelly Brazil
dd52fee563 osx netstat tests and fixtures 2020-05-20 17:25:25 -07:00
Kelly Brazil
8e1f885827 fix filtered netstat views 2020-05-20 16:43:53 -07:00
Kelly Brazil
2d39a58f90 doc update 2020-05-20 16:14:03 -07:00
Kelly Brazil
9c4fa2ae26 integer conversions and icmp fix 2020-05-20 15:39:47 -07:00
Kelly Brazil
de52d84e82 fix udp state and udp46 entries 2020-05-20 12:02:32 -07:00
Kelly Brazil
ce9b55059a organize files 2020-05-20 11:24:38 -07:00
Kelly Brazil
bcd370a6a0 code cleanup 2020-05-20 08:19:45 -07:00
Kelly Brazil
c8216850ab code cleanup 2020-05-20 07:19:24 -07:00
Kelly Brazil
f5feedb90b fix comments 2020-05-19 17:38:14 -07:00
Kelly Brazil
a4371cd187 support netstat -A 2020-05-19 17:36:16 -07:00
Kelly Brazil
9d5ba4c834 formatting 2020-05-19 17:14:04 -07:00
Kelly Brazil
1639dee1bb fix parse_post 2020-05-19 17:13:03 -07:00
Kelly Brazil
9363f430f2 use list extend method to simplify code 2020-05-19 16:26:41 -07:00
Kelly Brazil
9192a09073 parse all sections 2020-05-19 16:26:04 -07:00
Kelly Brazil
b915eb9755 initial osx parser 2020-05-19 15:15:08 -07:00
Kelly Brazil
1cfcc2b592 tighten up line test logic when counting tabs 2020-05-14 09:58:16 -07:00
Kelly Brazil
7138dd02b7 cleanup variables after adding to item 2020-05-14 09:51:10 -07:00
Kelly Brazil
b4276643b7 add dmidecode tests and fixtures 2020-05-14 09:43:13 -07:00
Kelly Brazil
2ef00763bf fix first item 2020-05-14 09:33:45 -07:00
Kelly Brazil
54364928fc fix oddities like hybrid single/multiline data and items containing multiple records 2020-05-14 08:57:23 -07:00
Kelly Brazil
09b3b4932b add dmidecode output fixtures 2020-05-13 10:51:38 -07:00
Kelly Brazil
29d6670119 convert integers 2020-05-13 10:18:49 -07:00
Kelly Brazil
2f654b5f1a doc update 2020-05-13 10:13:27 -07:00
Kelly Brazil
e53b9f5992 add caveats to documentation 2020-05-13 10:12:40 -07:00
Kelly Brazil
addb234e61 add dmidecode doc 2020-05-13 09:44:20 -07:00
Kelly Brazil
76eca3b659 add dmidecode 2020-05-13 09:43:35 -07:00
Kelly Brazil
f90dec4c0e add examples to documentation 2020-05-13 09:43:23 -07:00
Kelly Brazil
8900a59d4c simplify logic by removing redundant block 2020-05-13 09:31:12 -07:00
Kelly Brazil
6685138200 fix for missing multi-line values that come immediately after a previous multi-line value 2020-05-13 09:25:02 -07:00
Kelly Brazil
4d3e65b980 fix missing values 2020-05-13 09:00:32 -07:00
Kelly Brazil
e9282bb546 add dmidecode parser 2020-05-13 08:22:52 -07:00
Kelly Brazil
f5627a4594 version bump 2020-05-11 11:03:02 -07:00
Kelly Brazil
81ffdb2510 remove shebang for Fedora packaging 2020-05-11 10:54:26 -07:00
Kelly Brazil
4c00a99850 version bump 2020-05-11 10:37:14 -07:00
Kelly Brazil
2bfcb45b28 make cli.py executable 2020-05-11 10:32:42 -07:00
Kelly Brazil
ab0c10e791 remove execute permissions 2020-05-11 10:27:16 -07:00
Kelly Brazil
2c1935115d Merge pull request #61 from kellyjonbrazil/dev
Dev v1.10.10
2020-05-09 11:47:05 -07:00
Kelly Brazil
d98e43dc78 add netstat item 2020-05-09 11:42:56 -07:00
Kelly Brazil
9348988d64 add netstat test for Fedora32 2020-05-09 11:41:30 -07:00
Kelly Brazil
1285c66467 netstat with bluetooth section 2020-05-09 11:36:23 -07:00
Kelly Brazil
b7191bbc13 handle bluetooth section (ignore for now) 2020-05-09 11:36:03 -07:00
Kelly Brazil
98b97509f7 version bump 2020-05-09 11:25:13 -07:00
Kelly Brazil
2b2b570490 add tests for 'gone - no logout' 2020-05-09 11:22:26 -07:00
Kelly Brazil
cce2d1ff29 add condition for 'gone - no logout' 2020-05-09 11:22:01 -07:00
Kelly Brazil
b79600c572 version bump 2020-05-09 11:01:48 -07:00
Kelly Brazil
140f1a8543 test fixes for issue #60 2020-05-09 11:00:04 -07:00
Kelly Brazil
e34657cfde fix issue #60 that was skipping the first file in some instances using -R without -l 2020-05-08 15:26:11 -07:00
Kelly Brazil
99070fa607 version bump 2020-05-08 10:51:13 -07:00
Kelly Brazil
2b46785b1f add MIT license to vendorized IfconfigParser class 2020-05-08 10:49:30 -07:00
Kelly Brazil
c72562524b fully remove tests from packaging 2020-05-08 09:30:31 -07:00
Kelly Brazil
b7dd6441c7 version bump 2020-05-08 08:20:33 -07:00
Kelly Brazil
31fcc2f755 remove manifest.in - no longer needed due to removing tests 2020-05-08 08:20:21 -07:00
Kelly Brazil
b391aa14bc add license_file to metadata 2020-05-08 08:19:51 -07:00
Kelly Brazil
d3c45debbb remove tests and add license file 2020-05-08 08:19:31 -07:00
190 changed files with 42424 additions and 1053 deletions

1
.gitignore vendored
View File

@@ -3,5 +3,4 @@ __pycache__
dist/
build/
*.egg-info/
jc/parsers.old/
.github/

2
LICENSE.md Executable file → Normal file
View File

@@ -1,6 +1,6 @@
MIT License
Copyright (c) 2019 Kelly Brazil
Copyright (c) 2020 Kelly Brazil
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -1 +0,0 @@
graft tests/fixtures

248
README.md Executable file → Normal file
View File

@@ -4,9 +4,9 @@
# JC
JSON CLI output utility
`jc` is used to JSONify the output of many standard linux cli tools and file types for easier parsing in scripts. See the [**Parsers**](#parsers) section for supported commands and file types.
`jc` JSONifies the output of many CLI tools and file-types for easier parsing in scripts. See the [**Parsers**](#parsers) section for supported commands and file-types.
This allows further command line processing of output with tools like `jq` simply by piping commands:
This allows further command-line processing of output with tools like `jq` by piping commands:
```
$ ls -l /usr/bin | jc --ls | jq '.[] | select(.size > 50000000)'
{
@@ -66,21 +66,47 @@ Schemas for each parser can be found in the [`docs/parsers`](https://github.com/
Release notes can be found [here](https://blog.kellybrazil.com/category/jc-news/).
## Why Would Anyone Do This?!
For more information on the motivations for this project, please see my [blog post](https://blog.kellybrazil.com/2019/11/26/bringing-the-unix-philosophy-to-the-21st-century/).
## Installation
There are several ways to get `jc`. You can install via `pip`, `brew`, DEB or RPM packages, or by downloading the correct binary for your architecture and running it anywhere on your filesystem.
There are several ways to get `jc`. You can install via `pip`; other OS package repositories like `dnf`, `zypper`, `nix-env`, `brew`, or `portsnap`; via DEB/RPM packages; or by downloading the correct binary for your architecture and running it anywhere on your filesystem.
### Pip (macOS, linux, unix, Windows)
```
$ pip3 install --upgrade jc
$ pip3 install jc
```
### Brew (macOS)
### OS Package Repositories
#### Dnf (Fedora linux)
```
# dnf install jc
```
or
```
# dnf --enablerepo=updates-testing install jc
```
#### Zypper (openSUSE linux)
```
# zypper install jc
```
#### Nix-env (NixOS linux)
```
$ nix-env -iA nixpkgs.jc
```
#### Brew (macOS)
```
$ brew install jc
```
#### Ports (FreeBSD)
```
# portsnap fetch update && cd /usr/ports/textproc/py-jc && make install clean
```
### Packages and Binaries
Please see https://kellyjonbrazil.github.io/jc-packaging/ for details.
@@ -105,6 +131,7 @@ The JSON output can be compact (default) or pretty formatted with the `-p` optio
- `--csv` enables the `CSV` file parser
- `--df` enables the `df` command parser
- `--dig` enables the `dig` command parser
- `--dmidecode` enables the `dmidecode` command parser
- `--du` enables the `du` command parser
- `--env` enables the `env` command parser
- `--file` enables the `file` command parser
@@ -171,13 +198,22 @@ or
JC_COLORS=default,default,default,default
```
## Contributions
Feel free to add/improve code or parsers! You can use the [`jc/parsers/foo.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/foo.py) parser as a template and submit your parser with a pull request.
### Custom Parsers
Custom local parser plugins may be placed in a `jc/jcparsers` folder in your local **"App data directory"**:
- Linux/unix: `$HOME/.local/share/jc/jcparsers`
- macOS: `$HOME/Library/Application Support/jc/jcparsers`
- Windows: `$LOCALAPPDATA\jc\jc\jcparsers`
Local parser plugins are standard python module files. Use the [`jc/parsers/foo.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/foo.py) parser as a template and simply place a `.py` file in the `jcparsers` subfolder.
Local plugin filenames must be valid python module names, therefore must consist entirely of alphanumerics and start with a letter. Local plugins may override default plugins.
> Note: The application data directory follows the [XDG Base Directory Specification](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html)
## Compatibility
Some parsers like `ls`, `ps`, `dig`, etc. will work on any platform. Other parsers that are platform-specific will generate a warning message if they are used on an unsupported platform. To see all parser information, including compatibility, run `jc -ap`.
You may still use a parser on an unsupported platform - for example, you may want to parse a file with linux `lsof` output on an OSX laptop. In that case you can suppress the warning message with the `-q` cli option or the `quiet=True` function parameter in `parse()`:
```
@@ -187,16 +223,23 @@ $ cat lsof.out | jc --lsof -q
Tested on:
- Centos 7.7
- Ubuntu 18.4
- Fedora32
- OSX 10.11.6
- OSX 10.14.6
- NixOS
- FreeBSD12
## Contributions
Feel free to add/improve code or parsers! You can use the [`jc/parsers/foo.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/foo.py) parser as a template and submit your parser with a pull request.
## Acknowledgments
- CI automation and code optimizations from https://github.com/philippeitis
- `ifconfig-parser` module from https://github.com/KnightWhoSayNi/ifconfig-parser
- `xmltodict` module from https://github.com/martinblech/xmltodict by Martín Blech
- `ruamel.yaml` library from https://pypi.org/project/ruamel.yaml by Anthon van der Neut
- Parsing code from Conor Heine at https://gist.github.com/cahna/43a1a3ff4d075bcd71f9d7120037a501 adapted for some parsers
- Excellent constructive feedback from Ilya Sher (https://github.com/ilyash-b)
- Local parser plugin feature contributed by [Dean Serenevy](https://github.com/duelafn)
- CI automation and code optimizations by [philippeitis](https://github.com/philippeitis)
- [`ifconfig-parser`](https://github.com/KnightWhoSayNi/ifconfig-parser) module by KnightWhoSayNi
- [`xmltodict`](https://github.com/martinblech/xmltodict) module by Martín Blech
- [`ruamel.yaml`](https://pypi.org/project/ruamel.yaml) module by Anthon van der Neut
- Parsing [code](https://gist.github.com/cahna/43a1a3ff4d075bcd71f9d7120037a501) from Conor Heine adapted for some parsers
- Excellent constructive feedback from [Ilya Sher](https://github.com/ilyash-b)
## Examples
### airport -I
@@ -295,21 +338,25 @@ $ arp -a | jc --arp -p # or: jc -p arp -a
"address": "192.168.71.1",
"hwtype": "ether",
"hwaddress": "00:50:56:c0:00:08",
"iface": "ens33"
"iface": "ens33",
"permanent": true
},
{
"name": null,
"address": "192.168.71.254",
"hwtype": "ether",
"hwaddress": "00:50:56:fe:7a:b4",
"iface": "ens33"
"iface": "ens33",
"permanent": true
},
{
"name": "_gateway",
"address": "192.168.71.2",
"hwtype": "ether",
"hwaddress": "00:50:56:f7:4a:fc",
"iface": "ens33"
"iface": "ens33",
"permanent": false,
"expires": 110
}
]
```
@@ -340,7 +387,7 @@ $ blkid | jc --blkid -p # or: jc -p blkid
]
```
```
$ sudo blkid -o udev -ip /dev/sda2 | jc --blkid -p # or: sudo jc -p blkid -o udev -ip /dev/sda2
# blkid -o udev -ip /dev/sda2 | jc --blkid -p # or: jc -p blkid -o udev -ip /dev/sda2
[
{
"id_fs_uuid": "3klkIj-w1kk-DkJi-0XBJ-y3i7-i2Ac-vHqWBM",
@@ -735,6 +782,52 @@ $ dig -x 1.1.1.1 | jc --dig -p # or: jc -p dig -x 1.1.1.1
}
]
```
### dmidecode
```
# dmidecode | jc --dmidecode -p # or: jc -p dmidecode
[
{
"handle": "0x0000",
"type": 0,
"bytes": 24,
"description": "BIOS Information",
"values": {
"vendor": "Phoenix Technologies LTD",
"version": "6.00",
"release_date": "04/13/2018",
"address": "0xEA490",
"runtime_size": "88944 bytes",
"rom_size": "64 kB",
"characteristics": [
"ISA is supported",
"PCI is supported",
"PC Card (PCMCIA) is supported",
"PNP is supported",
"APM is supported",
"BIOS is upgradeable",
"BIOS shadowing is allowed",
"ESCD support is available",
"Boot from CD is supported",
"Selectable boot is supported",
"EDD is supported",
"Print screen service is supported (int 5h)",
"8042 keyboard services are supported (int 9h)",
"Serial services are supported (int 14h)",
"Printer services are supported (int 17h)",
"CGA/mono video services are supported (int 10h)",
"ACPI is supported",
"Smart battery is supported",
"BIOS boot specification is supported",
"Function key-initiated network boot is supported",
"Targeted content distribution is supported"
],
"bios_revision": "4.6",
"firmware_revision": "0.0"
}
},
...
]
```
### du
```
$ du /usr | jc --du -p # or: jc -p du /usr
@@ -1150,7 +1243,7 @@ $ cat example.ini | jc --ini -p
```
### iptables
```
$ sudo iptables --line-numbers -v -L -t nat | jc --iptables -p # or: sudo jc -p iptables --line-numbers -v -L -t nat
# iptables --line-numbers -v -L -t nat | jc --iptables -p # or: jc -p iptables --line-numbers -v -L -t nat
[
{
"chain": "PREROUTING",
@@ -1380,7 +1473,7 @@ $ lsmod | jc --lsmod -p # or: jc -p lsmod
```
### lsof
```
$ sudo lsof | jc --lsof -p # or: sudo jc -p lsof
# lsof | jc --lsof -p # or: jc -p lsof
[
{
"command": "systemd",
@@ -1467,7 +1560,7 @@ $ mount | jc --mount -p # or: jc -p mount
```
### netstat
```
$ sudo netstat -apee | jc --netstat -p # or: sudo jc -p netstat -apee
# netstat -apee | jc --netstat -p # or: jc -p netstat -apee
[
{
"proto": "tcp",
@@ -1616,6 +1709,85 @@ $ sudo netstat -apee | jc --netstat -p # or: sudo jc -p netstat -apee
},
...
]
$ netstat -r | jc --netstat -p # or: jc -p netstat -r
[
{
"destination": "default",
"gateway": "gateway",
"genmask": "0.0.0.0",
"route_flags": "UG",
"mss": 0,
"window": 0,
"irtt": 0,
"iface": "ens33",
"kind": "route",
"route_flags_pretty": [
"UP",
"GATEWAY"
]
},
{
"destination": "172.17.0.0",
"gateway": "0.0.0.0",
"genmask": "255.255.0.0",
"route_flags": "U",
"mss": 0,
"window": 0,
"irtt": 0,
"iface": "docker0",
"kind": "route",
"route_flags_pretty": [
"UP"
]
},
{
"destination": "192.168.71.0",
"gateway": "0.0.0.0",
"genmask": "255.255.255.0",
"route_flags": "U",
"mss": 0,
"window": 0,
"irtt": 0,
"iface": "ens33",
"kind": "route",
"route_flags_pretty": [
"UP"
]
}
]
$ netstat -i | jc --netstat -p # or: jc -p netstat -i
[
{
"iface": "ens33",
"mtu": 1500,
"rx_ok": 476,
"rx_err": 0,
"rx_drp": 0,
"rx_ovr": 0,
"tx_ok": 312,
"tx_err": 0,
"tx_drp": 0,
"tx_ovr": 0,
"flg": "BMRU",
"kind": "interface"
},
{
"iface": "lo",
"mtu": 65536,
"rx_ok": 0,
"rx_err": 0,
"rx_drp": 0,
"rx_ovr": 0,
"tx_ok": 0,
"tx_err": 0,
"tx_drp": 0,
"tx_ovr": 0,
"flg": "LRU",
"kind": "interface"
}
]
```
### ntpq
```
@@ -1821,48 +1993,42 @@ $ route -ee | jc --route -p # or: jc -p route -ee
[
{
"destination": "default",
"gateway": "gateway",
"gateway": "_gateway",
"genmask": "0.0.0.0",
"flags": "UG",
"metric": 100,
"metric": 202,
"ref": 0,
"use": 0,
"iface": "ens33",
"mss": 0,
"window": 0,
"irtt": 0
},
{
"destination": "172.17.0.0",
"gateway": "0.0.0.0",
"genmask": "255.255.0.0",
"flags": "U",
"metric": 0,
"ref": 0,
"use": 0,
"iface": "docker",
"mss": 0,
"window": 0,
"irtt": 0
"irtt": 0,
"flags_pretty": [
"UP",
"GATEWAY"
]
},
{
"destination": "192.168.71.0",
"gateway": "0.0.0.0",
"genmask": "255.255.255.0",
"flags": "U",
"metric": 100,
"metric": 202,
"ref": 0,
"use": 0,
"iface": "ens33",
"mss": 0,
"window": 0,
"irtt": 0
"irtt": 0,
"flags_pretty": [
"UP"
]
}
]
```
### /etc/shadow file
```
$ sudo cat /etc/shadow | jc --shadow -p
# cat /etc/shadow | jc --shadow -p
[
{
"username": "root",
@@ -1899,7 +2065,7 @@ $ sudo cat /etc/shadow | jc --shadow -p
```
### ss
```
$ sudo ss -a | jc --ss -p # or: sudo jc -p ss -a
# ss -a | jc --ss -p # or: jc -p ss -a
[
{
"netid": "nl",

View File

@@ -1,5 +1,80 @@
jc changelog
20200612 v1.11.5
- Update airport_s parser to fix error on parsing empty data
- Update arp parser to fix error on parsing empty data
- Update blkid parser to fix error on parsing empty data
- Update crontab parser to fix error on parsing empty data
- Update crontab_u parser to fix error on parsing empty data
- Update df parser to fix error on parsing empty data
- Update free parser to fix error on parsing empty data
- Update lsblk parser to fix error on parsing empty data
- Update lsmod parser to fix error on parsing empty data
- Update mount parser to fix error on parsing empty data
- Update netstat parser to fix error on parsing empty data
- Update ntpq parser to fix error on parsing empty data
- Update ps parser to fix error on parsing empty data
- Update route parser to fix error on parsing empty data
- Update systemctl parser to fix error on parsing empty data
- Update systemctl_lj parser to fix error on parsing empty data
- Update systemctl_ls parser to fix error on parsing empty data
- Update systemctl_luf parser to fix error on parsing empty data
- Update uptime parser to fix error on parsing empty data
- Update w parser to fix error on parsing empty data
- Update xml parser to fix error on parsing empty data
- Add tests to all parsers for no data condition
- Update ss parser to fix integer fields
20200610 v1.11.4
- Update ls parser to fix error on parsing an empty directory
20200609 v1.11.3
- Add local parser plugin feature (contributed by Dean Serenevy)
20200530 v1.11.2
- Update netstat parser to add freebsd support
- Update netstat parser to add route_flags_pretty field
- Update netstat parser to change osx_inode field name to unix_inode
- Update netstat parser to change osx_flags field name to unix_flags
- Update netstat parser to strip whitespace from state field
- Update route parser to add flags_pretty field
- Update arp parser to add permanent field (freebsd and osx)
- Update arp parser to add expires field (freebsd)
- Update w parser to strip whitespace from what field
- Update last parser to fix FreeBSD issues
- Update stat parser to change osx_flags field name to unix_flags
- Update stat parser to add unix_device field for freebsd and osx
- Fix freebsd compatibility message for df, fstab, mount, ntpq, stat, and uname parsers
- Fix compatibility message for platforms that include the version number at the end (e.g. freebsd12)
20200523 v1.11.1
- Update stat command parser to change osx_flags field to string
20200522 v1.11.0
- Add dmidecode command parser
- Update stat command parser to add OSX support
- Update netstat command parser to add OSX support
- Update netstat command parser to add -r (route) functionality for linux and OSX
- Update netstat command parser to add -i (interface) functionality for linux and OSX
20200511 v1.10.12
- Remove shebang from jc/cli.py for Fedora packaging
20200511 v1.10.11
- Change file permissions for Fedora packaging
20200509 v1.10.10
- Fix ls parser issue where the first file was skipped for ls -R on some platforms
- Update last parser to handle 'gone - no logout' condition
- Update netstat parser to handle bluetooth section (ignore gracefully for now)
20200508 v1.10.9
- Add license info to vendorized ifconfig-parser class
20200508 v1.10.8
- Add license file to dist for Fedora RPM packaging requirements
- Remove tests from package to keep from polluting the global site-packages
20200501 v1.10.7
- Requirements modifications for Fedora RPM packaging requirements

View File

@@ -13,6 +13,7 @@ pydocmd simple jc.parsers.crontab_u+ > ../docs/parsers/crontab_u.md
pydocmd simple jc.parsers.csv+ > ../docs/parsers/csv.md
pydocmd simple jc.parsers.df+ > ../docs/parsers/df.md
pydocmd simple jc.parsers.dig+ > ../docs/parsers/dig.md
pydocmd simple jc.parsers.dmidecode+ > ../docs/parsers/dmidecode.md
pydocmd simple jc.parsers.du+ > ../docs/parsers/du.md
pydocmd simple jc.parsers.env+ > ../docs/parsers/env.md
pydocmd simple jc.parsers.file+ > ../docs/parsers/file.md

View File

@@ -59,6 +59,8 @@ Examples:
"hwtype": "ether",
"hwaddress": "00:50:56:f0:98:26",
"iface": "ens33"
"permanent": false,
"expires": 1182
},
{
"name": "gateway",
@@ -66,6 +68,8 @@ Examples:
"hwtype": "ether",
"hwaddress": "00:50:56:f7:4a:fc",
"iface": "ens33"
"permanent": false,
"expires": 110
}
]
@@ -77,6 +81,8 @@ Examples:
"hwtype": "ether",
"hwaddress": "00:50:56:fe:7a:b4",
"iface": "ens33"
"permanent": false,
"expires": "1182"
},
{
"name": "_gateway",
@@ -84,6 +90,8 @@ Examples:
"hwtype": "ether",
"hwaddress": "00:50:56:f7:4a:fc",
"iface": "ens33"
"permanent": false,
"expires": "110"
}
]
@@ -114,7 +122,9 @@ Returns:
"hwtype": string,
"hwaddress": string,
"flags_mask": string,
"iface": string
"iface": string,
"permanent": boolean,
"expires": integer
}
]

View File

@@ -7,7 +7,7 @@ Usage:
Compatibility:
'linux', 'darwin'
'linux', 'darwin', 'freebsd'
Examples:

153
docs/parsers/dmidecode.md Normal file
View File

@@ -0,0 +1,153 @@
# jc.parsers.dmidecode
jc - JSON CLI output utility dmidecode Parser
Usage:
specify --dmidecode as the first argument if the piped input is coming from dmidecode
Compatibility:
'linux'
Examples:
# dmidecode | jc --dmidecode -p
[
{
"handle": "0x0000",
"type": 0,
"bytes": 24,
"description": "BIOS Information",
"values": {
"vendor": "Phoenix Technologies LTD",
"version": "6.00",
"release_date": "04/13/2018",
"address": "0xEA490",
"runtime_size": "88944 bytes",
"rom_size": "64 kB",
"characteristics": [
"ISA is supported",
"PCI is supported",
"PC Card (PCMCIA) is supported",
"PNP is supported",
"APM is supported",
"BIOS is upgradeable",
"BIOS shadowing is allowed",
"ESCD support is available",
"Boot from CD is supported",
"Selectable boot is supported",
"EDD is supported",
"Print screen service is supported (int 5h)",
"8042 keyboard services are supported (int 9h)",
"Serial services are supported (int 14h)",
"Printer services are supported (int 17h)",
"CGA/mono video services are supported (int 10h)",
"ACPI is supported",
"Smart battery is supported",
"BIOS boot specification is supported",
"Function key-initiated network boot is supported",
"Targeted content distribution is supported"
],
"bios_revision": "4.6",
"firmware_revision": "0.0"
}
},
...
]
# dmidecode | jc --dmidecode -p -r
[
{
"handle": "0x0000",
"type": "0",
"bytes": "24",
"description": "BIOS Information",
"values": {
"vendor": "Phoenix Technologies LTD",
"version": "6.00",
"release_date": "04/13/2018",
"address": "0xEA490",
"runtime_size": "88944 bytes",
"rom_size": "64 kB",
"characteristics": [
"ISA is supported",
"PCI is supported",
"PC Card (PCMCIA) is supported",
"PNP is supported",
"APM is supported",
"BIOS is upgradeable",
"BIOS shadowing is allowed",
"ESCD support is available",
"Boot from CD is supported",
"Selectable boot is supported",
"EDD is supported",
"Print screen service is supported (int 5h)",
"8042 keyboard services are supported (int 9h)",
"Serial services are supported (int 14h)",
"Printer services are supported (int 17h)",
"CGA/mono video services are supported (int 10h)",
"ACPI is supported",
"Smart battery is supported",
"BIOS boot specification is supported",
"Function key-initiated network boot is supported",
"Targeted content distribution is supported"
],
"bios_revision": "4.6",
"firmware_revision": "0.0"
}
},
...
]
## info
```python
info(self, /, *args, **kwargs)
```
## process
```python
process(proc_data)
```
Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
[
{
"handle": string,
"type": integer,
"bytes": integer,
"description": string,
"values": { (null if empty)
"lowercase_no_spaces_keys": string,
"multiline_key_values": [
string,
]
}
}
]
## 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:
List of dictionaries. Raw or processed structured data.

View File

@@ -7,7 +7,7 @@ Usage:
Compatibility:
'linux'
'linux', 'freebsd'
Examples:

View File

@@ -7,7 +7,7 @@ Usage:
Compatibility:
'linux', 'darwin'
'linux', 'darwin', 'freebsd'
Example:

View File

@@ -5,13 +5,18 @@ Usage:
Specify --netstat as the first argument if the piped input is coming from netstat
Caveats:
- Use of multiple 'l' options is not supported on OSX (e.g. 'netstat -rlll')
- Use of the 'A' option is not supported on OSX when using the 'r' option (e.g. netstat -rA)
Compatibility:
'linux'
'linux', 'darwin', 'freebsd'
Examples:
$ sudo netstat -apee | jc --netstat -p
# netstat -apee | jc --netstat -p
[
{
"proto": "tcp",
@@ -161,152 +166,83 @@ Examples:
...
]
$ sudo netstat -apee | jc --netstat -p -r
$ netstat -r | jc --netstat -p
[
{
"proto": "tcp",
"recv_q": "0",
"send_q": "0",
"local_address": "localhost",
"foreign_address": "0.0.0.0",
"state": "LISTEN",
"user": "systemd-resolve",
"inode": "26958",
"program_name": "systemd-resolve",
"kind": "network",
"pid": "887",
"local_port": "domain",
"foreign_port": "*",
"transport_protocol": "tcp",
"network_protocol": "ipv4"
"destination": "default",
"gateway": "gateway",
"genmask": "0.0.0.0",
"route_flags": "UG",
"mss": 0,
"window": 0,
"irtt": 0,
"iface": "ens33",
"kind": "route",
"route_flags_pretty": [
"UP",
"GATEWAY"
]
},
{
"proto": "tcp",
"recv_q": "0",
"send_q": "0",
"local_address": "0.0.0.0",
"foreign_address": "0.0.0.0",
"state": "LISTEN",
"user": "root",
"inode": "30499",
"program_name": "sshd",
"kind": "network",
"pid": "1186",
"local_port": "ssh",
"foreign_port": "*",
"transport_protocol": "tcp",
"network_protocol": "ipv4"
"destination": "172.17.0.0",
"gateway": "0.0.0.0",
"genmask": "255.255.0.0",
"route_flags": "U",
"mss": 0,
"window": 0,
"irtt": 0,
"iface": "docker0",
"kind": "route",
"route_flags_pretty": [
"UP"
]
},
{
"proto": "tcp",
"recv_q": "0",
"send_q": "0",
"local_address": "localhost",
"foreign_address": "localhost",
"state": "ESTABLISHED",
"user": "root",
"inode": "46829",
"program_name": "sshd: root",
"kind": "network",
"pid": "2242",
"local_port": "ssh",
"foreign_port": "52186",
"transport_protocol": "tcp",
"network_protocol": "ipv4"
"destination": "192.168.71.0",
"gateway": "0.0.0.0",
"genmask": "255.255.255.0",
"route_flags": "U",
"mss": 0,
"window": 0,
"irtt": 0,
"iface": "ens33",
"kind": "route",
"route_flags_pretty": [
"UP"
]
}
]
$ netstat -i | jc --netstat -p
[
{
"iface": "ens33",
"mtu": 1500,
"rx_ok": 476,
"rx_err": 0,
"rx_drp": 0,
"rx_ovr": 0,
"tx_ok": 312,
"tx_err": 0,
"tx_drp": 0,
"tx_ovr": 0,
"flg": "BMRU",
"kind": "interface"
},
{
"proto": "tcp",
"recv_q": "0",
"send_q": "0",
"local_address": "localhost",
"foreign_address": "localhost",
"state": "ESTABLISHED",
"user": "root",
"inode": "46828",
"program_name": "ssh",
"kind": "network",
"pid": "2241",
"local_port": "52186",
"foreign_port": "ssh",
"transport_protocol": "tcp",
"network_protocol": "ipv4"
},
{
"proto": "tcp6",
"recv_q": "0",
"send_q": "0",
"local_address": "[::]",
"foreign_address": "[::]",
"state": "LISTEN",
"user": "root",
"inode": "30510",
"program_name": "sshd",
"kind": "network",
"pid": "1186",
"local_port": "ssh",
"foreign_port": "*",
"transport_protocol": "tcp",
"network_protocol": "ipv6"
},
{
"proto": "udp",
"recv_q": "0",
"send_q": "0",
"local_address": "localhost",
"foreign_address": "0.0.0.0",
"state": null,
"user": "systemd-resolve",
"inode": "26957",
"program_name": "systemd-resolve",
"kind": "network",
"pid": "887",
"local_port": "domain",
"foreign_port": "*",
"transport_protocol": "udp",
"network_protocol": "ipv4"
},
{
"proto": "raw6",
"recv_q": "0",
"send_q": "0",
"local_address": "[::]",
"foreign_address": "[::]",
"state": "7",
"user": "systemd-network",
"inode": "27001",
"program_name": "systemd-network",
"kind": "network",
"pid": "867",
"local_port": "ipv6-icmp",
"foreign_port": "*",
"transport_protocol": null,
"network_protocol": "ipv6"
},
{
"proto": "unix",
"refcnt": "2",
"flags": null,
"type": "DGRAM",
"state": null,
"inode": "33322",
"program_name": "systemd",
"path": "/run/user/1000/systemd/notify",
"kind": "socket",
"pid": " 1607"
},
{
"proto": "unix",
"refcnt": "2",
"flags": "ACC",
"type": "SEQPACKET",
"state": "LISTENING",
"inode": "20835",
"program_name": "init",
"path": "/run/udev/control",
"kind": "socket",
"pid": " 1"
},
...
"iface": "lo",
"mtu": 65536,
"rx_ok": 0,
"rx_err": 0,
"rx_drp": 0,
"rx_ovr": 0,
"tx_ok": 0,
"tx_err": 0,
"tx_drp": 0,
"tx_ovr": 0,
"flg": "LRU",
"kind": "interface"
}
]
## info
@@ -331,28 +267,100 @@ Returns:
[
{
"proto": string,
"recv_q": integer,
"send_q": integer,
"transport_protocol" string,
"network_protocol": string,
"local_address": string,
"local_port": string,
"local_port_num": integer,
"foreign_address": string,
"foreign_port": string,
"foreign_port_num": integer,
"state": string,
"program_name": string,
"pid": integer,
"user": string,
"security_context": string,
"refcnt": integer,
"flags": string,
"type": string,
"inode": integer,
"path": string,
"kind": string
"proto": string,
"recv_q": integer,
"send_q": integer,
"transport_protocol" string,
"network_protocol": string,
"local_address": string,
"local_port": string,
"local_port_num": integer,
"foreign_address": string,
"foreign_port": string,
"foreign_port_num": integer,
"state": string,
"program_name": string,
"pid": integer,
"user": string,
"security_context": string,
"refcnt": integer,
"flags": string,
"type": string,
"inode": integer,
"path": string,
"kind": string,
"address": string,
"unix_inode": string,
"conn": string,
"refs": string,
"nextref": string,
"name": string,
"unit": integer,
"vendor": integer,
"class": integer,
"subcla": integer,
"unix_flags": integer,
"pcbcount": integer,
"rcvbuf": integer,
"sndbuf": integer,
"rxbytes": integer,
"txbytes": integer,
"destination": string,
"gateway": string,
"route_flags": string,
"route_flags_pretty": [
string,
]
"route_refs": integer,
"use": integer,
"mtu": integer,
"expire": string,
"genmask": string,
"mss": integer,
"window": integer,
"irtt": integer,
"iface": string,
"metric": integer,
"network": string,
"address": string,
"ipkts": integer, - = null
"ierrs": integer, - = null
"idrop": integer, - = null
"opkts": integer, - = null
"oerrs": integer, - = null
"coll": integer, - = null
"rx_ok": integer,
"rx_err": integer,
"rx_drp": integer,
"rx_ovr": integer,
"tx_ok": integer,
"tx_err": integer,
"tx_drp": integer,
"tx_ovr": integer,
"flg": string,
"ibytes": integer,
"obytes": integer,
"r_mbuf": integer,
"s_mbuf": integer,
"r_clus": integer,
"s_clus": integer,
"r_hiwa": integer,
"s_hiwa": integer,
"r_lowa": integer,
"s_lowa": integer,
"r_bcnt": integer,
"s_bcnt": integer,
"r_bmax": integer,
"s_bmax": integer,
"rexmit": integer,
"ooorcv": integer,
"0_win": integer,
"rexmt": float,
"persist": float,
"keep": float,
"2msl": float,
"delack": float,
"rcvtime": float,
}
]

View File

@@ -7,7 +7,7 @@ Usage:
Compatibility:
'linux'
'linux', 'freebsd'
Examples:

View File

@@ -15,53 +15,48 @@ Examples:
[
{
"destination": "default",
"gateway": "gateway",
"gateway": "_gateway",
"genmask": "0.0.0.0",
"flags": "UG",
"metric": 100,
"metric": 202,
"ref": 0,
"use": 0,
"iface": "ens33",
"mss": 0,
"window": 0,
"irtt": 0
},
{
"destination": "172.17.0.0",
"gateway": "0.0.0.0",
"genmask": "255.255.0.0",
"flags": "U",
"metric": 0,
"ref": 0,
"use": 0,
"iface": "docker",
"mss": 0,
"window": 0,
"irtt": 0
"irtt": 0,
"flags_pretty": [
"UP",
"GATEWAY"
]
},
{
"destination": "192.168.71.0",
"gateway": "0.0.0.0",
"genmask": "255.255.255.0",
"flags": "U",
"metric": 100,
"metric": 202,
"ref": 0,
"use": 0,
"iface": "ens33",
"mss": 0,
"window": 0,
"irtt": 0
"irtt": 0,
"flags_pretty": [
"UP"
]
}
]
$ route -ee | jc --route -p -r
[
{
"destination": "default",
"gateway": "gateway",
"gateway": "_gateway",
"genmask": "0.0.0.0",
"flags": "UG",
"metric": "100",
"metric": "202",
"ref": "0",
"use": "0",
"iface": "ens33",
@@ -69,25 +64,12 @@ Examples:
"window": "0",
"irtt": "0"
},
{
"destination": "172.17.0.0",
"gateway": "0.0.0.0",
"genmask": "255.255.0.0",
"flags": "U",
"metric": "0",
"ref": "0",
"use": "0",
"iface": "docker",
"mss": "0",
"window": "0",
"irtt": "0"
},
{
"destination": "192.168.71.0",
"gateway": "0.0.0.0",
"genmask": "255.255.255.0",
"flags": "U",
"metric": "100",
"metric": "202",
"ref": "0",
"use": "0",
"iface": "ens33",
@@ -97,6 +79,7 @@ Examples:
}
]
## info
```python
info(self, /, *args, **kwargs)
@@ -119,17 +102,20 @@ Returns:
[
{
"destination": string,
"gateway": string,
"genmask": string,
"flags": string,
"metric": integer,
"ref": integer,
"use": integer,
"mss": integer,
"window": integer,
"irtt": integer,
"iface": string
"destination": string,
"gateway": string,
"genmask": string,
"flags": string,
"flags_pretty": [
string,
]
"metric": integer,
"ref": integer,
"use": integer,
"mss": integer,
"window": integer,
"irtt": integer,
"iface": string
}
]

View File

@@ -7,7 +7,7 @@ Usage:
Compatibility:
'linux'
'linux', 'darwin', 'freebsd'
Examples:
@@ -141,7 +141,11 @@ Returns:
"access_time": string, # - = null
"modify_time": string, # - = null
"change_time": string, # - = null
"birth_time": string # - = null
"birth_time": string, # - = null
"unix_device": integer,
"rdev": integer,
"block_size": integer,
"unix_flags": string
}
]

View File

@@ -11,7 +11,7 @@ Limitations:
Compatibility:
'linux', 'darwin'
'linux', 'darwin', 'freebsd'
Example:

611
jc/appdirs.py Normal file
View File

@@ -0,0 +1,611 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2005-2010 ActiveState Software Inc.
# Copyright (c) 2013 Eddy Petrișor
'''
# This is the MIT license
Copyright (c) 2010 ActiveState Software Inc.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
'''
"""Utilities for determining application-specific dirs.
See <https://github.com/ActiveState/appdirs> for details and usage.
"""
# Dev Notes:
# - MSDN on where to store app data files:
# http://support.microsoft.com/default.aspx?scid=kb;en-us;310294#XSLTH3194121123120121120120
# - Mac OS X: http://developer.apple.com/documentation/MacOSX/Conceptual/BPFileSystem/index.html
# - XDG spec for Un*x: https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
__version__ = "1.4.4"
__version_info__ = tuple(int(segment) for segment in __version__.split("."))
import sys
import os
PY3 = sys.version_info[0] == 3
if PY3:
unicode = str
if sys.platform.startswith('java'):
import platform
os_name = platform.java_ver()[3][0]
if os_name.startswith('Windows'): # "Windows XP", "Windows 7", etc.
system = 'win32'
elif os_name.startswith('Mac'): # "Mac OS X", etc.
system = 'darwin'
else: # "Linux", "SunOS", "FreeBSD", etc.
# Setting this to "linux2" is not ideal, but only Windows or Mac
# are actually checked for and the rest of the module expects
# *sys.platform* style strings.
system = 'linux2'
else:
system = sys.platform
def user_data_dir(appname=None, appauthor=None, version=None, roaming=False):
r"""Return full path to the user-specific data dir for this application.
"appname" is the name of application.
If None, just the system directory is returned.
"appauthor" (only used on Windows) is the name of the
appauthor or distributing body for this application. Typically
it is the owning company name. This falls back to appname. You may
pass False to disable it.
"version" is an optional version path element to append to the
path. You might want to use this if you want multiple versions
of your app to be able to run independently. If used, this
would typically be "<major>.<minor>".
Only applied when appname is present.
"roaming" (boolean, default False) can be set True to use the Windows
roaming appdata directory. That means that for users on a Windows
network setup for roaming profiles, this user data will be
sync'd on login. See
<http://technet.microsoft.com/en-us/library/cc766489(WS.10).aspx>
for a discussion of issues.
Typical user data directories are:
Mac OS X: ~/Library/Application Support/<AppName>
Unix: ~/.local/share/<AppName> # or in $XDG_DATA_HOME, if defined
Win XP (not roaming): C:\Documents and Settings\<username>\Application Data\<AppAuthor>\<AppName>
Win XP (roaming): C:\Documents and Settings\<username>\Local Settings\Application Data\<AppAuthor>\<AppName>
Win 7 (not roaming): C:\Users\<username>\AppData\Local\<AppAuthor>\<AppName>
Win 7 (roaming): C:\Users\<username>\AppData\Roaming\<AppAuthor>\<AppName>
For Unix, we follow the XDG spec and support $XDG_DATA_HOME.
That means, by default "~/.local/share/<AppName>".
"""
if system == "win32":
if appauthor is None:
appauthor = appname
const = roaming and "CSIDL_APPDATA" or "CSIDL_LOCAL_APPDATA"
path = os.path.normpath(_get_win_folder(const))
if appname:
if appauthor is not False:
path = os.path.join(path, appauthor, appname)
else:
path = os.path.join(path, appname)
elif system == 'darwin':
path = os.path.expanduser('~/Library/Application Support/')
if appname:
path = os.path.join(path, appname)
else:
path = os.getenv('XDG_DATA_HOME', os.path.expanduser("~/.local/share"))
if appname:
path = os.path.join(path, appname)
if appname and version:
path = os.path.join(path, version)
return path
def site_data_dir(appname=None, appauthor=None, version=None, multipath=False):
r"""Return full path to the user-shared data dir for this application.
"appname" is the name of application.
If None, just the system directory is returned.
"appauthor" (only used on Windows) is the name of the
appauthor or distributing body for this application. Typically
it is the owning company name. This falls back to appname. You may
pass False to disable it.
"version" is an optional version path element to append to the
path. You might want to use this if you want multiple versions
of your app to be able to run independently. If used, this
would typically be "<major>.<minor>".
Only applied when appname is present.
"multipath" is an optional parameter only applicable to *nix
which indicates that the entire list of data dirs should be
returned. By default, the first item from XDG_DATA_DIRS is
returned, or '/usr/local/share/<AppName>',
if XDG_DATA_DIRS is not set
Typical site data directories are:
Mac OS X: /Library/Application Support/<AppName>
Unix: /usr/local/share/<AppName> or /usr/share/<AppName>
Win XP: C:\Documents and Settings\All Users\Application Data\<AppAuthor>\<AppName>
Vista: (Fail! "C:\ProgramData" is a hidden *system* directory on Vista.)
Win 7: C:\ProgramData\<AppAuthor>\<AppName> # Hidden, but writeable on Win 7.
For Unix, this is using the $XDG_DATA_DIRS[0] default.
WARNING: Do not use this on Windows. See the Vista-Fail note above for why.
"""
if system == "win32":
if appauthor is None:
appauthor = appname
path = os.path.normpath(_get_win_folder("CSIDL_COMMON_APPDATA"))
if appname:
if appauthor is not False:
path = os.path.join(path, appauthor, appname)
else:
path = os.path.join(path, appname)
elif system == 'darwin':
path = os.path.expanduser('/Library/Application Support')
if appname:
path = os.path.join(path, appname)
else:
# XDG default for $XDG_DATA_DIRS
# only first, if multipath is False
path = os.getenv('XDG_DATA_DIRS',
os.pathsep.join(['/usr/local/share', '/usr/share']))
pathlist = [os.path.expanduser(x.rstrip(os.sep)) for x in path.split(os.pathsep)]
if appname:
if version:
appname = os.path.join(appname, version)
pathlist = [os.sep.join([x, appname]) for x in pathlist]
if multipath:
path = os.pathsep.join(pathlist)
else:
path = pathlist[0]
return path
if appname and version:
path = os.path.join(path, version)
return path
def user_config_dir(appname=None, appauthor=None, version=None, roaming=False):
r"""Return full path to the user-specific config dir for this application.
"appname" is the name of application.
If None, just the system directory is returned.
"appauthor" (only used on Windows) is the name of the
appauthor or distributing body for this application. Typically
it is the owning company name. This falls back to appname. You may
pass False to disable it.
"version" is an optional version path element to append to the
path. You might want to use this if you want multiple versions
of your app to be able to run independently. If used, this
would typically be "<major>.<minor>".
Only applied when appname is present.
"roaming" (boolean, default False) can be set True to use the Windows
roaming appdata directory. That means that for users on a Windows
network setup for roaming profiles, this user data will be
sync'd on login. See
<http://technet.microsoft.com/en-us/library/cc766489(WS.10).aspx>
for a discussion of issues.
Typical user config directories are:
Mac OS X: ~/Library/Preferences/<AppName>
Unix: ~/.config/<AppName> # or in $XDG_CONFIG_HOME, if defined
Win *: same as user_data_dir
For Unix, we follow the XDG spec and support $XDG_CONFIG_HOME.
That means, by default "~/.config/<AppName>".
"""
if system == "win32":
path = user_data_dir(appname, appauthor, None, roaming)
elif system == 'darwin':
path = os.path.expanduser('~/Library/Preferences/')
if appname:
path = os.path.join(path, appname)
else:
path = os.getenv('XDG_CONFIG_HOME', os.path.expanduser("~/.config"))
if appname:
path = os.path.join(path, appname)
if appname and version:
path = os.path.join(path, version)
return path
def site_config_dir(appname=None, appauthor=None, version=None, multipath=False):
r"""Return full path to the user-shared data dir for this application.
"appname" is the name of application.
If None, just the system directory is returned.
"appauthor" (only used on Windows) is the name of the
appauthor or distributing body for this application. Typically
it is the owning company name. This falls back to appname. You may
pass False to disable it.
"version" is an optional version path element to append to the
path. You might want to use this if you want multiple versions
of your app to be able to run independently. If used, this
would typically be "<major>.<minor>".
Only applied when appname is present.
"multipath" is an optional parameter only applicable to *nix
which indicates that the entire list of config dirs should be
returned. By default, the first item from XDG_CONFIG_DIRS is
returned, or '/etc/xdg/<AppName>', if XDG_CONFIG_DIRS is not set
Typical site config directories are:
Mac OS X: same as site_data_dir
Unix: /etc/xdg/<AppName> or $XDG_CONFIG_DIRS[i]/<AppName> for each value in
$XDG_CONFIG_DIRS
Win *: same as site_data_dir
Vista: (Fail! "C:\ProgramData" is a hidden *system* directory on Vista.)
For Unix, this is using the $XDG_CONFIG_DIRS[0] default, if multipath=False
WARNING: Do not use this on Windows. See the Vista-Fail note above for why.
"""
if system == 'win32':
path = site_data_dir(appname, appauthor)
if appname and version:
path = os.path.join(path, version)
elif system == 'darwin':
path = os.path.expanduser('/Library/Preferences')
if appname:
path = os.path.join(path, appname)
else:
# XDG default for $XDG_CONFIG_DIRS
# only first, if multipath is False
path = os.getenv('XDG_CONFIG_DIRS', '/etc/xdg')
pathlist = [os.path.expanduser(x.rstrip(os.sep)) for x in path.split(os.pathsep)]
if appname:
if version:
appname = os.path.join(appname, version)
pathlist = [os.sep.join([x, appname]) for x in pathlist]
if multipath:
path = os.pathsep.join(pathlist)
else:
path = pathlist[0]
return path
def user_cache_dir(appname=None, appauthor=None, version=None, opinion=True):
r"""Return full path to the user-specific cache dir for this application.
"appname" is the name of application.
If None, just the system directory is returned.
"appauthor" (only used on Windows) is the name of the
appauthor or distributing body for this application. Typically
it is the owning company name. This falls back to appname. You may
pass False to disable it.
"version" is an optional version path element to append to the
path. You might want to use this if you want multiple versions
of your app to be able to run independently. If used, this
would typically be "<major>.<minor>".
Only applied when appname is present.
"opinion" (boolean) can be False to disable the appending of
"Cache" to the base app data dir for Windows. See
discussion below.
Typical user cache directories are:
Mac OS X: ~/Library/Caches/<AppName>
Unix: ~/.cache/<AppName> (XDG default)
Win XP: C:\Documents and Settings\<username>\Local Settings\Application Data\<AppAuthor>\<AppName>\Cache
Vista: C:\Users\<username>\AppData\Local\<AppAuthor>\<AppName>\Cache
On Windows the only suggestion in the MSDN docs is that local settings go in
the `CSIDL_LOCAL_APPDATA` directory. This is identical to the non-roaming
app data dir (the default returned by `user_data_dir` above). Apps typically
put cache data somewhere *under* the given dir here. Some examples:
...\Mozilla\Firefox\Profiles\<ProfileName>\Cache
...\Acme\SuperApp\Cache\1.0
OPINION: This function appends "Cache" to the `CSIDL_LOCAL_APPDATA` value.
This can be disabled with the `opinion=False` option.
"""
if system == "win32":
if appauthor is None:
appauthor = appname
path = os.path.normpath(_get_win_folder("CSIDL_LOCAL_APPDATA"))
if appname:
if appauthor is not False:
path = os.path.join(path, appauthor, appname)
else:
path = os.path.join(path, appname)
if opinion:
path = os.path.join(path, "Cache")
elif system == 'darwin':
path = os.path.expanduser('~/Library/Caches')
if appname:
path = os.path.join(path, appname)
else:
path = os.getenv('XDG_CACHE_HOME', os.path.expanduser('~/.cache'))
if appname:
path = os.path.join(path, appname)
if appname and version:
path = os.path.join(path, version)
return path
def user_state_dir(appname=None, appauthor=None, version=None, roaming=False):
r"""Return full path to the user-specific state dir for this application.
"appname" is the name of application.
If None, just the system directory is returned.
"appauthor" (only used on Windows) is the name of the
appauthor or distributing body for this application. Typically
it is the owning company name. This falls back to appname. You may
pass False to disable it.
"version" is an optional version path element to append to the
path. You might want to use this if you want multiple versions
of your app to be able to run independently. If used, this
would typically be "<major>.<minor>".
Only applied when appname is present.
"roaming" (boolean, default False) can be set True to use the Windows
roaming appdata directory. That means that for users on a Windows
network setup for roaming profiles, this user data will be
sync'd on login. See
<http://technet.microsoft.com/en-us/library/cc766489(WS.10).aspx>
for a discussion of issues.
Typical user state directories are:
Mac OS X: same as user_data_dir
Unix: ~/.local/state/<AppName> # or in $XDG_STATE_HOME, if defined
Win *: same as user_data_dir
For Unix, we follow this Debian proposal <https://wiki.debian.org/XDGBaseDirectorySpecification#state>
to extend the XDG spec and support $XDG_STATE_HOME.
That means, by default "~/.local/state/<AppName>".
"""
if system in ["win32", "darwin"]:
path = user_data_dir(appname, appauthor, None, roaming)
else:
path = os.getenv('XDG_STATE_HOME', os.path.expanduser("~/.local/state"))
if appname:
path = os.path.join(path, appname)
if appname and version:
path = os.path.join(path, version)
return path
def user_log_dir(appname=None, appauthor=None, version=None, opinion=True):
r"""Return full path to the user-specific log dir for this application.
"appname" is the name of application.
If None, just the system directory is returned.
"appauthor" (only used on Windows) is the name of the
appauthor or distributing body for this application. Typically
it is the owning company name. This falls back to appname. You may
pass False to disable it.
"version" is an optional version path element to append to the
path. You might want to use this if you want multiple versions
of your app to be able to run independently. If used, this
would typically be "<major>.<minor>".
Only applied when appname is present.
"opinion" (boolean) can be False to disable the appending of
"Logs" to the base app data dir for Windows, and "log" to the
base cache dir for Unix. See discussion below.
Typical user log directories are:
Mac OS X: ~/Library/Logs/<AppName>
Unix: ~/.cache/<AppName>/log # or under $XDG_CACHE_HOME if defined
Win XP: C:\Documents and Settings\<username>\Local Settings\Application Data\<AppAuthor>\<AppName>\Logs
Vista: C:\Users\<username>\AppData\Local\<AppAuthor>\<AppName>\Logs
On Windows the only suggestion in the MSDN docs is that local settings
go in the `CSIDL_LOCAL_APPDATA` directory. (Note: I'm interested in
examples of what some windows apps use for a logs dir.)
OPINION: This function appends "Logs" to the `CSIDL_LOCAL_APPDATA`
value for Windows and appends "log" to the user cache dir for Unix.
This can be disabled with the `opinion=False` option.
"""
if system == "darwin":
path = os.path.join(
os.path.expanduser('~/Library/Logs'),
appname)
elif system == "win32":
path = user_data_dir(appname, appauthor, version)
version = False
if opinion:
path = os.path.join(path, "Logs")
else:
path = user_cache_dir(appname, appauthor, version)
version = False
if opinion:
path = os.path.join(path, "log")
if appname and version:
path = os.path.join(path, version)
return path
class AppDirs(object):
"""Convenience wrapper for getting application dirs."""
def __init__(self, appname=None, appauthor=None, version=None,
roaming=False, multipath=False):
self.appname = appname
self.appauthor = appauthor
self.version = version
self.roaming = roaming
self.multipath = multipath
@property
def user_data_dir(self):
return user_data_dir(self.appname, self.appauthor,
version=self.version, roaming=self.roaming)
@property
def site_data_dir(self):
return site_data_dir(self.appname, self.appauthor,
version=self.version, multipath=self.multipath)
@property
def user_config_dir(self):
return user_config_dir(self.appname, self.appauthor,
version=self.version, roaming=self.roaming)
@property
def site_config_dir(self):
return site_config_dir(self.appname, self.appauthor,
version=self.version, multipath=self.multipath)
@property
def user_cache_dir(self):
return user_cache_dir(self.appname, self.appauthor,
version=self.version)
@property
def user_state_dir(self):
return user_state_dir(self.appname, self.appauthor,
version=self.version)
@property
def user_log_dir(self):
return user_log_dir(self.appname, self.appauthor,
version=self.version)
#---- internal support stuff
def _get_win_folder_from_registry(csidl_name):
"""This is a fallback technique at best. I'm not sure if using the
registry for this guarantees us the correct answer for all CSIDL_*
names.
"""
if PY3:
import winreg as _winreg
else:
import _winreg
shell_folder_name = {
"CSIDL_APPDATA": "AppData",
"CSIDL_COMMON_APPDATA": "Common AppData",
"CSIDL_LOCAL_APPDATA": "Local AppData",
}[csidl_name]
key = _winreg.OpenKey(
_winreg.HKEY_CURRENT_USER,
r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
)
dir, type = _winreg.QueryValueEx(key, shell_folder_name)
return dir
def _get_win_folder_with_ctypes(csidl_name):
import ctypes
csidl_const = {
"CSIDL_APPDATA": 26,
"CSIDL_COMMON_APPDATA": 35,
"CSIDL_LOCAL_APPDATA": 28,
}[csidl_name]
buf = ctypes.create_unicode_buffer(1024)
ctypes.windll.shell32.SHGetFolderPathW(None, csidl_const, None, 0, buf)
# Downgrade to short path name if have highbit chars. See
# <http://bugs.activestate.com/show_bug.cgi?id=85099>.
has_high_char = False
for c in buf:
if ord(c) > 255:
has_high_char = True
break
if has_high_char:
buf2 = ctypes.create_unicode_buffer(1024)
if ctypes.windll.kernel32.GetShortPathNameW(buf.value, buf2, 1024):
buf = buf2
return buf.value
def _get_win_folder_with_jna(csidl_name):
import array
from com.sun import jna
from com.sun.jna.platform import win32
buf_size = win32.WinDef.MAX_PATH * 2
buf = array.zeros('c', buf_size)
shell = win32.Shell32.INSTANCE
shell.SHGetFolderPath(None, getattr(win32.ShlObj, csidl_name), None, win32.ShlObj.SHGFP_TYPE_CURRENT, buf)
dir = jna.Native.toString(buf.tostring()).rstrip("\0")
# Downgrade to short path name if have highbit chars. See
# <http://bugs.activestate.com/show_bug.cgi?id=85099>.
has_high_char = False
for c in dir:
if ord(c) > 255:
has_high_char = True
break
if has_high_char:
buf = array.zeros('c', buf_size)
kernel = win32.Kernel32.INSTANCE
if kernel.GetShortPathName(dir, buf, buf_size):
dir = jna.Native.toString(buf.tostring()).rstrip("\0")
return dir
if system == "win32":
try:
from ctypes import windll
except ImportError:
try:
import com.sun.jna
except ImportError:
_get_win_folder = _get_win_folder_from_registry
else:
_get_win_folder = _get_win_folder_with_jna
else:
_get_win_folder = _get_win_folder_with_ctypes
#---- self test code
if __name__ == "__main__":
appname = "MyApp"
appauthor = "MyCompany"
props = ("user_data_dir",
"user_config_dir",
"user_cache_dir",
"user_state_dir",
"user_log_dir",
"site_data_dir",
"site_config_dir")
print("-- app dirs %s --" % __version__)
print("-- app dirs (with optional 'version')")
dirs = AppDirs(appname, appauthor, version="1.0")
for prop in props:
print("%s: %s" % (prop, getattr(dirs, prop)))
print("\n-- app dirs (without optional 'version')")
dirs = AppDirs(appname, appauthor)
for prop in props:
print("%s: %s" % (prop, getattr(dirs, prop)))
print("\n-- app dirs (without optional 'appauthor')")
dirs = AppDirs(appname)
for prop in props:
print("%s: %s" % (prop, getattr(dirs, prop)))
print("\n-- app dirs (with disabled 'appauthor')")
dirs = AppDirs(appname, appauthor=False)
for prop in props:
print("%s: %s" % (prop, getattr(dirs, prop)))

View File

@@ -1,9 +1,11 @@
#!/usr/bin/env python3
"""jc - JSON CLI output utility
JC cli module
"""
import sys
import os
import os.path
import re
import shlex
import importlib
import textwrap
@@ -15,10 +17,11 @@ from pygments.token import (Name, Number, String, Keyword)
from pygments.lexers import JsonLexer
from pygments.formatters import Terminal256Formatter
import jc.utils
import jc.appdirs as appdirs
class info():
version = '1.10.7'
version = '1.11.5'
description = 'jc cli output JSON conversion tool'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -36,6 +39,7 @@ parsers = [
'csv',
'df',
'dig',
'dmidecode',
'du',
'env',
'file',
@@ -79,6 +83,20 @@ parsers = [
'yaml'
]
# List of custom or override parsers.
# Allow any <user_data_dir>/jc/jcparsers/*.py
local_parsers = []
data_dir = appdirs.user_data_dir("jc", "jc")
local_parsers_dir = os.path.join(data_dir, "jcparsers")
if os.path.isdir(local_parsers_dir):
sys.path.append(data_dir)
for name in os.listdir(local_parsers_dir):
if re.match(r'\w+\.py', name) and os.path.isfile(os.path.join(local_parsers_dir, name)):
plugin_name = name[0:-3]
local_parsers.append(plugin_name)
if plugin_name not in parsers:
parsers.append(plugin_name)
def set_env_colors():
"""
@@ -122,10 +140,10 @@ def set_env_colors():
# Try the color set in the JC_COLORS env variable first. If it is set to default, then fall back to default colors
return {
Name.Tag: f'bold ansi{color_list[0]}' if not color_list[0] == 'default' else f'bold ansiblue', # key names
Keyword: f'ansi{color_list[1]}' if not color_list[1] == 'default' else f'ansibrightblack', # true, false, null
Number: f'ansi{color_list[2]}' if not color_list[2] == 'default' else f'ansimagenta', # numbers
String: f'ansi{color_list[3]}' if not color_list[3] == 'default' else f'ansigreen' # strings
Name.Tag: f'bold ansi{color_list[0]}' if not color_list[0] == 'default' else 'bold ansiblue', # key names
Keyword: f'ansi{color_list[1]}' if not color_list[1] == 'default' else 'ansibrightblack', # true, false, null
Number: f'ansi{color_list[2]}' if not color_list[2] == 'default' else 'ansimagenta', # numbers
String: f'ansi{color_list[3]}' if not color_list[3] == 'default' else 'ansigreen' # strings
}
@@ -159,8 +177,9 @@ def parser_mod_shortname(parser):
def parser_module(parser):
"""import the module just in time and return the module object"""
importlib.import_module('jc.parsers.' + parser_mod_shortname(parser))
return getattr(jc.parsers, parser_mod_shortname(parser))
shortname = parser_mod_shortname(parser)
path = ('jcparsers.' if shortname in local_parsers else 'jc.parsers.')
return importlib.import_module(path + shortname)
def parsers_text(indent=0, pad=0):
@@ -245,7 +264,7 @@ def helptext(message):
def json_out(data, pretty=False, mono=False, piped_out=False):
# set colors
# set colors
class JcStyle(Style):
styles = set_env_colors()

View File

@@ -88,7 +88,7 @@ import jc.parsers.universal
class info():
version = '1.0'
version = '1.1'
description = 'airport -s command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -170,15 +170,17 @@ def parse(data, raw=False, quiet=False):
if not quiet:
jc.utils.compatibility(__name__, info.compatible)
cleandata = data.splitlines()
raw_output = []
cleandata = list(filter(None, data.splitlines()))
# fix headers
cleandata[0] = cleandata[0].lower()
cleandata[0] = cleandata[0].replace('-', '_')
cleandata[0] = cleandata[0].replace('security (auth/unicast/group)', 'security')
if cleandata:
# fix headers
cleandata[0] = cleandata[0].lower()
cleandata[0] = cleandata[0].replace('-', '_')
cleandata[0] = cleandata[0].replace('security (auth/unicast/group)', 'security')
# parse the data
raw_output = jc.parsers.universal.sparse_table_parse(cleandata)
# parse the data
raw_output = jc.parsers.universal.sparse_table_parse(cleandata)
if raw:
return raw_output

View File

@@ -58,6 +58,8 @@ Examples:
"hwtype": "ether",
"hwaddress": "00:50:56:f0:98:26",
"iface": "ens33"
"permanent": false,
"expires": 1182
},
{
"name": "gateway",
@@ -65,6 +67,8 @@ Examples:
"hwtype": "ether",
"hwaddress": "00:50:56:f7:4a:fc",
"iface": "ens33"
"permanent": false,
"expires": 110
}
]
@@ -76,6 +80,8 @@ Examples:
"hwtype": "ether",
"hwaddress": "00:50:56:fe:7a:b4",
"iface": "ens33"
"permanent": false,
"expires": "1182"
},
{
"name": "_gateway",
@@ -83,6 +89,8 @@ Examples:
"hwtype": "ether",
"hwaddress": "00:50:56:f7:4a:fc",
"iface": "ens33"
"permanent": false,
"expires": "110"
}
]
"""
@@ -91,7 +99,7 @@ import jc.parsers.universal
class info():
version = '1.3'
version = '1.5'
description = 'arp command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -123,7 +131,9 @@ def process(proc_data):
"hwtype": string,
"hwaddress": string,
"flags_mask": string,
"iface": string
"iface": string,
"permanent": boolean,
"expires": integer
}
]
"""
@@ -133,6 +143,14 @@ def process(proc_data):
if 'name' in entry and entry['name'] == '?':
entry['name'] = None
int_list = ['expires']
for key in int_list:
if key in entry:
try:
entry[key] = int(entry[key])
except (ValueError):
entry[key] = None
return proc_data
@@ -153,60 +171,65 @@ def parse(data, raw=False, quiet=False):
if not quiet:
jc.utils.compatibility(__name__, info.compatible)
cleandata = data.splitlines()
raw_output = []
cleandata = list(filter(None, data.splitlines()))
# remove final Entries row if -v was used
if cleandata[-1].startswith('Entries:'):
cleandata.pop(-1)
if cleandata:
# detect if osx style was used
if cleandata[0][-1] == ']':
raw_output = []
for line in cleandata:
splitline = line.split()
output_line = {
'name': splitline[0],
'address': splitline[1].lstrip('(').rstrip(')'),
'hwtype': splitline[-1].lstrip('[').rstrip(']'),
'hwaddress': splitline[3],
'iface': splitline[5]
}
raw_output.append(output_line)
# remove final Entries row if -v was used
if cleandata[-1].startswith('Entries:'):
cleandata.pop(-1)
if raw:
return raw_output
# detect if freebsd/osx style was used
if cleandata[0][-1] == ']':
for line in cleandata:
splitline = line.split()
output_line = {
'name': splitline[0],
'address': splitline[1].lstrip('(').rstrip(')'),
'hwtype': splitline[-1].lstrip('[').rstrip(']'),
'hwaddress': splitline[3],
'iface': splitline[5]
}
if 'permanent' in splitline:
output_line['permanent'] = True
else:
output_line['permanent'] = False
if 'expires' in splitline:
output_line['expires'] = splitline[-3]
raw_output.append(output_line)
if raw:
return raw_output
else:
return process(raw_output)
# detect if linux style was used
elif cleandata[0].startswith('Address'):
# fix header row to change Flags Mask to flags_mask
cleandata[0] = cleandata[0].replace('Flags Mask', 'flags_mask')
cleandata[0] = cleandata[0].lower()
raw_output = jc.parsers.universal.simple_table_parse(cleandata)
# otherwise, try bsd style
else:
return process(raw_output)
for line in cleandata:
line = line.split()
output_line = {
'name': line[0],
'address': line[1].lstrip('(').rstrip(')'),
'hwtype': line[4].lstrip('[').rstrip(']'),
'hwaddress': line[3],
'iface': line[6],
}
raw_output.append(output_line)
# detect if linux style was used
elif cleandata[0].startswith('Address'):
# fix header row to change Flags Mask to flags_mask
cleandata[0] = cleandata[0].replace('Flags Mask', 'flags_mask')
cleandata[0] = cleandata[0].lower()
raw_output = jc.parsers.universal.simple_table_parse(cleandata)
if raw:
return raw_output
else:
return process(raw_output)
# otherwise, try bsd style
if raw:
return raw_output
else:
raw_output = []
for line in cleandata:
line = line.split()
output_line = {
'name': line[0],
'address': line[1].lstrip('(').rstrip(')'),
'hwtype': line[4].lstrip('[').rstrip(']'),
'hwaddress': line[3],
'iface': line[6],
}
raw_output.append(output_line)
if raw:
return raw_output
else:
return process(raw_output)
return process(raw_output)

View File

@@ -79,7 +79,7 @@ import jc.utils
class info():
version = '1.0'
version = '1.1'
description = 'blkid command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -176,7 +176,7 @@ def parse(data, raw=False, quiet=False):
raw_output = []
if data:
if list(filter(None, data.splitlines())):
# if the first field is a device, use normal parsing:
if data.split(maxsplit=1)[0][-1] == ':':
linedata = data.splitlines()

View File

@@ -132,7 +132,7 @@ import jc.parsers.universal
class info():
version = '1.2'
version = '1.3'
description = 'crontab command and file parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -225,44 +225,45 @@ def parse(data, raw=False, quiet=False):
# Clear any blank lines
cleandata = list(filter(None, cleandata))
# Clear any commented lines
for i, line in reversed(list(enumerate(cleandata))):
if line.strip().startswith('#'):
cleandata.pop(i)
if cleandata:
# Clear any commented lines
for i, line in reversed(list(enumerate(cleandata))):
if line.strip().startswith('#'):
cleandata.pop(i)
# Pop any variable assignment lines
cron_var = []
for i, line in reversed(list(enumerate(cleandata))):
if '=' in line:
var_line = cleandata.pop(i)
var_name = var_line.split('=', maxsplit=1)[0].strip()
var_value = var_line.split('=', maxsplit=1)[1].strip()
cron_var.append({'name': var_name,
'value': var_value})
# Pop any variable assignment lines
cron_var = []
for i, line in reversed(list(enumerate(cleandata))):
if '=' in line:
var_line = cleandata.pop(i)
var_name = var_line.split('=', maxsplit=1)[0].strip()
var_value = var_line.split('=', maxsplit=1)[1].strip()
cron_var.append({'name': var_name,
'value': var_value})
raw_output['variables'] = cron_var
raw_output['variables'] = cron_var
# Pop any shortcut lines
shortcut_list = []
for i, line in reversed(list(enumerate(cleandata))):
if line.strip().startswith('@'):
shortcut_line = cleandata.pop(i)
occurrence = shortcut_line.split(maxsplit=1)[0].strip().lstrip('@')
cmd = shortcut_line.split(maxsplit=1)[1].strip()
shortcut_list.append({'occurrence': occurrence,
'command': cmd})
# Pop any shortcut lines
shortcut_list = []
for i, line in reversed(list(enumerate(cleandata))):
if line.strip().startswith('@'):
shortcut_line = cleandata.pop(i)
occurrence = shortcut_line.split(maxsplit=1)[0].strip().lstrip('@')
cmd = shortcut_line.split(maxsplit=1)[1].strip()
shortcut_list.append({'occurrence': occurrence,
'command': cmd})
# Add header row for parsing
cleandata[:0] = ['minute hour day_of_month month day_of_week command']
# Add header row for parsing
cleandata[:0] = ['minute hour day_of_month month day_of_week command']
if len(cleandata) > 1:
cron_list = jc.parsers.universal.simple_table_parse(cleandata)
if len(cleandata) > 1:
cron_list = jc.parsers.universal.simple_table_parse(cleandata)
raw_output['schedule'] = cron_list
raw_output['schedule'] = cron_list
# Add shortcut entries back in
for item in shortcut_list:
raw_output['schedule'].append(item)
# Add shortcut entries back in
for item in shortcut_list:
raw_output['schedule'].append(item)
if raw:
return raw_output

View File

@@ -133,7 +133,7 @@ import jc.parsers.universal
class info():
version = '1.1'
version = '1.2'
description = 'crontab file parser with user support'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -226,46 +226,47 @@ def parse(data, raw=False, quiet=False):
# Clear any blank lines
cleandata = list(filter(None, cleandata))
# Clear any commented lines
for i, line in reversed(list(enumerate(cleandata))):
if line.strip().startswith('#'):
cleandata.pop(i)
if cleandata:
# Clear any commented lines
for i, line in reversed(list(enumerate(cleandata))):
if line.strip().startswith('#'):
cleandata.pop(i)
# Pop any variable assignment lines
cron_var = []
for i, line in reversed(list(enumerate(cleandata))):
if '=' in line:
var_line = cleandata.pop(i)
var_name = var_line.split('=', maxsplit=1)[0].strip()
var_value = var_line.split('=', maxsplit=1)[1].strip()
cron_var.append({'name': var_name,
'value': var_value})
# Pop any variable assignment lines
cron_var = []
for i, line in reversed(list(enumerate(cleandata))):
if '=' in line:
var_line = cleandata.pop(i)
var_name = var_line.split('=', maxsplit=1)[0].strip()
var_value = var_line.split('=', maxsplit=1)[1].strip()
cron_var.append({'name': var_name,
'value': var_value})
raw_output['variables'] = cron_var
raw_output['variables'] = cron_var
# Pop any shortcut lines
shortcut_list = []
for i, line in reversed(list(enumerate(cleandata))):
if line.strip().startswith('@'):
shortcut_line = cleandata.pop(i)
occurrence = shortcut_line.split(maxsplit=1)[0].strip().lstrip('@')
usr = shortcut_line.split(maxsplit=2)[1].strip()
cmd = shortcut_line.split(maxsplit=2)[2].strip()
shortcut_list.append({'occurrence': occurrence,
'user': usr,
'command': cmd})
# Pop any shortcut lines
shortcut_list = []
for i, line in reversed(list(enumerate(cleandata))):
if line.strip().startswith('@'):
shortcut_line = cleandata.pop(i)
occurrence = shortcut_line.split(maxsplit=1)[0].strip().lstrip('@')
usr = shortcut_line.split(maxsplit=2)[1].strip()
cmd = shortcut_line.split(maxsplit=2)[2].strip()
shortcut_list.append({'occurrence': occurrence,
'user': usr,
'command': cmd})
# Add header row for parsing
cleandata[:0] = ['minute hour day_of_month month day_of_week user command']
# Add header row for parsing
cleandata[:0] = ['minute hour day_of_month month day_of_week user command']
if len(cleandata) > 1:
cron_list = jc.parsers.universal.simple_table_parse(cleandata)
if len(cleandata) > 1:
cron_list = jc.parsers.universal.simple_table_parse(cleandata)
raw_output['schedule'] = cron_list
raw_output['schedule'] = cron_list
# Add shortcut entries back in
for item in shortcut_list:
raw_output['schedule'].append(item)
# Add shortcut entries back in
for item in shortcut_list:
raw_output['schedule'].append(item)
if raw:
return raw_output

View File

@@ -6,7 +6,7 @@ Usage:
Compatibility:
'linux', 'darwin'
'linux', 'darwin', 'freebsd'
Examples:
@@ -73,13 +73,13 @@ import jc.parsers.universal
class info():
version = '1.2'
version = '1.4'
description = 'df command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
compatible = ['linux', 'darwin']
compatible = ['linux', 'darwin', 'freebsd']
magic_commands = ['df']
@@ -184,14 +184,16 @@ def parse(data, raw=False, quiet=False):
jc.utils.compatibility(__name__, info.compatible)
cleandata = data.splitlines()
raw_output = []
# fix headers
cleandata[0] = cleandata[0].lower()
cleandata[0] = cleandata[0].replace('-', '_')
cleandata[0] = cleandata[0].replace('mounted on', 'mounted_on')
if list(filter(None, cleandata)):
# fix headers
cleandata[0] = cleandata[0].lower()
cleandata[0] = cleandata[0].replace('-', '_')
cleandata[0] = cleandata[0].replace('mounted on', 'mounted_on')
# parse the data
raw_output = jc.parsers.universal.sparse_table_parse(cleandata)
# parse the data
raw_output = jc.parsers.universal.sparse_table_parse(cleandata)
if raw:
return raw_output

339
jc/parsers/dmidecode.py Normal file
View File

@@ -0,0 +1,339 @@
"""jc - JSON CLI output utility dmidecode Parser
Usage:
specify --dmidecode as the first argument if the piped input is coming from dmidecode
Compatibility:
'linux'
Examples:
# dmidecode | jc --dmidecode -p
[
{
"handle": "0x0000",
"type": 0,
"bytes": 24,
"description": "BIOS Information",
"values": {
"vendor": "Phoenix Technologies LTD",
"version": "6.00",
"release_date": "04/13/2018",
"address": "0xEA490",
"runtime_size": "88944 bytes",
"rom_size": "64 kB",
"characteristics": [
"ISA is supported",
"PCI is supported",
"PC Card (PCMCIA) is supported",
"PNP is supported",
"APM is supported",
"BIOS is upgradeable",
"BIOS shadowing is allowed",
"ESCD support is available",
"Boot from CD is supported",
"Selectable boot is supported",
"EDD is supported",
"Print screen service is supported (int 5h)",
"8042 keyboard services are supported (int 9h)",
"Serial services are supported (int 14h)",
"Printer services are supported (int 17h)",
"CGA/mono video services are supported (int 10h)",
"ACPI is supported",
"Smart battery is supported",
"BIOS boot specification is supported",
"Function key-initiated network boot is supported",
"Targeted content distribution is supported"
],
"bios_revision": "4.6",
"firmware_revision": "0.0"
}
},
...
]
# dmidecode | jc --dmidecode -p -r
[
{
"handle": "0x0000",
"type": "0",
"bytes": "24",
"description": "BIOS Information",
"values": {
"vendor": "Phoenix Technologies LTD",
"version": "6.00",
"release_date": "04/13/2018",
"address": "0xEA490",
"runtime_size": "88944 bytes",
"rom_size": "64 kB",
"characteristics": [
"ISA is supported",
"PCI is supported",
"PC Card (PCMCIA) is supported",
"PNP is supported",
"APM is supported",
"BIOS is upgradeable",
"BIOS shadowing is allowed",
"ESCD support is available",
"Boot from CD is supported",
"Selectable boot is supported",
"EDD is supported",
"Print screen service is supported (int 5h)",
"8042 keyboard services are supported (int 9h)",
"Serial services are supported (int 14h)",
"Printer services are supported (int 17h)",
"CGA/mono video services are supported (int 10h)",
"ACPI is supported",
"Smart battery is supported",
"BIOS boot specification is supported",
"Function key-initiated network boot is supported",
"Targeted content distribution is supported"
],
"bios_revision": "4.6",
"firmware_revision": "0.0"
}
},
...
]
"""
import jc.utils
class info():
version = '1.0'
description = 'dmidecode command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
# details = 'enter any other details here'
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
compatible = ['linux']
magic_commands = ['dmidecode']
__version__ = info.version
def process(proc_data):
"""
Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
[
{
"handle": string,
"type": integer,
"bytes": integer,
"description": string,
"values": { (null if empty)
"lowercase_no_spaces_keys": string,
"multiline_key_values": [
string,
]
}
}
]
"""
for entry in proc_data:
int_list = ['type', 'bytes']
for key in int_list:
if key in entry:
try:
key_int = int(entry[key])
entry[key] = key_int
except (ValueError):
entry[key] = None
if not entry['values']:
entry['values'] = None
return proc_data
def 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:
List of dictionaries. Raw or processed structured data.
"""
if not quiet:
jc.utils.compatibility(__name__, info.compatible)
item_header = False
item_values = False
value_list = False
item = None
header = None
key = None
val = None
attribute = None
values = None
key_data = None
raw_output = []
data = data.splitlines()
# remove header rows
for row in data.copy():
if row:
data.pop(0)
else:
break
# main parsing loop
for line in data:
# new item
if not line:
item_header = True
item_values = False
value_list = False
if item:
if values:
item['values'][attribute] = values
if key_data:
item['values'][f'{key}_data'] = key_data
raw_output.append(item)
item = {}
header = None
key = None
val = None
attribute = None
values = []
key_data = []
continue
# header
if line.startswith('Handle ') and line.endswith('bytes'):
# Handle 0x0000, DMI type 0, 24 bytes
header = line.replace(',', ' ').split()
item = {
'handle': header[1],
'type': header[4],
'bytes': header[5]
}
continue
# description
if item_header:
item_header = False
item_values = True
value_list = False
item['description'] = line
item['values'] = {}
continue
# new item if multiple descriptions in handle
if not item_header and not line.startswith('\t'):
item_header = False
item_values = True
value_list = False
if item:
if values:
item['values'][attribute] = values
if key_data:
item['values'][f'{key}_data'] = key_data
raw_output.append(item)
item = {
'handle': header[1],
'type': header[4],
'bytes': header[5],
'description': line,
'values': {}
}
key = None
val = None
attribute = None
values = []
key_data = []
continue
# keys and values
if item_values \
and len(line.split(':', maxsplit=1)) == 2 \
and line.startswith('\t') \
and not line.startswith('\t\t') \
and not line.strip().endswith(':'):
item_header = False
item_values = True
value_list = False
if values:
item['values'][attribute] = values
values = []
if key_data:
item['values'][f'{key}_data'] = key_data
key_data = []
key = line.split(':', maxsplit=1)[0].strip().lower().replace(' ', '_')
val = line.split(':', maxsplit=1)[1].strip()
item['values'].update({key: val})
continue
# multi-line key
if item_values \
and line.startswith('\t') \
and not line.startswith('\t\t') \
and line.strip().endswith(':'):
item_header = False
item_values = True
value_list = True
if values:
item['values'][attribute] = values
values = []
if key_data:
item['values'][f'{key}_data'] = key_data
key_data = []
attribute = line[:-1].strip().lower().replace(' ', '_')
values = []
continue
# multi-line values
if value_list \
and line.startswith('\t\t'):
values.append(line.strip())
continue
# data for hybrid multi-line objects
if item_values \
and not value_list \
and line.startswith('\t\t'):
if f'{key}_data' not in item['values']:
item['values'][f'{key}_data'] = []
key_data.append(line.strip())
continue
if item:
raw_output.append(item)
if raw:
return raw_output
else:
return process(raw_output)

View File

@@ -53,7 +53,7 @@ import jc.parsers.universal
class info():
version = '1.0'
version = '1.1'
description = 'free command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -122,14 +122,17 @@ def parse(data, raw=False, quiet=False):
jc.utils.compatibility(__name__, info.compatible)
cleandata = data.splitlines()
cleandata[0] = cleandata[0].lower()
cleandata[0] = cleandata[0].replace('buff/cache', 'buff_cache')
cleandata[0] = 'type ' + cleandata[0]
raw_output = []
raw_output = jc.parsers.universal.simple_table_parse(cleandata)
if cleandata:
cleandata[0] = cleandata[0].lower()
cleandata[0] = cleandata[0].replace('buff/cache', 'buff_cache')
cleandata[0] = 'type ' + cleandata[0]
for entry in raw_output:
entry['type'] = entry['type'].rstrip(':')
raw_output = jc.parsers.universal.simple_table_parse(cleandata)
for entry in raw_output:
entry['type'] = entry['type'].rstrip(':')
if raw:
return raw_output

View File

@@ -6,7 +6,7 @@ Usage:
Compatibility:
'linux'
'linux', 'freebsd'
Examples:
@@ -70,13 +70,13 @@ import jc.utils
class info():
version = '1.1'
version = '1.2'
description = 'fstab file parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
compatible = ['linux']
compatible = ['linux', 'freebsd']
__version__ = info.version

View File

@@ -162,9 +162,31 @@ __version__ = info.version
class IfconfigParser(object):
# Author: threeheadedknight@protonmail.com
# Date created: 30.06.2018 17:03
# Python Version: 3.7
# Author: threeheadedknight@protonmail.com
# Date created: 30.06.2018 17:03
# Python Version: 3.7
# MIT License
# Copyright (c) 2018 threeheadedknight@protonmail.com
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
attributes = ['name', 'type', 'mac_addr', 'ipv4_addr', 'ipv4_bcast', 'ipv4_mask', 'ipv6_addr', 'ipv6_mask',
'ipv6_scope', 'state', 'mtu', 'metric', 'rx_packets', 'rx_errors', 'rx_dropped', 'rx_overruns',

View File

@@ -72,7 +72,7 @@ import jc.utils
class info():
version = '1.0'
version = '1.2'
description = 'last and lastb command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -110,6 +110,9 @@ def process(proc_data):
]
"""
for entry in proc_data:
if 'user' in entry and entry['user'] == 'boot_time':
entry['user'] = 'boot time'
if 'tty' in entry and entry['tty'] == '~':
entry['tty'] = None
@@ -122,6 +125,9 @@ def process(proc_data):
if 'logout' in entry and entry['logout'] == 'still_logged_in':
entry['logout'] = 'still logged in'
if 'logout' in entry and entry['logout'] == 'gone_-_no_logout':
entry['logout'] = 'gone - no logout'
return proc_data
@@ -152,16 +158,23 @@ def parse(data, raw=False, quiet=False):
for entry in cleandata:
output_line = {}
if entry.startswith('wtmp begins ') or entry.startswith('btmp begins '):
if entry.startswith('wtmp begins ') or entry.startswith('btmp begins ') or entry.startswith('utx.log begins '):
continue
entry = entry.replace('system boot', 'system_boot')
entry = entry.replace('boot time', 'boot_time')
entry = entry.replace(' still logged in', '- still_logged_in')
entry = entry.replace(' gone - no logout', '- gone_-_no_logout')
linedata = entry.split()
if re.match(r'[MTWFS][ouerha][nedritnu] [JFMASOND][aepuco][nbrynlgptvc]', ' '.join(linedata[2:4])):
linedata.insert(2, '-')
# freebsd fix
if linedata[0] == 'boot_time':
linedata.insert(1, '-')
linedata.insert(1, '~')
output_line['user'] = linedata[0]
output_line['tty'] = linedata[1]
output_line['hostname'] = linedata[2]

View File

@@ -149,7 +149,7 @@ import jc.utils
class info():
version = '1.3'
version = '1.5'
description = 'ls command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -226,19 +226,19 @@ def parse(data, raw=False, quiet=False):
linedata = data.splitlines()
# Delete first line if it starts with 'total 1234'
if linedata:
# Delete first line if it starts with 'total 1234'
if re.match(r'total [0-9]+', linedata[0]):
linedata.pop(0)
# Look for parent line if glob or -R is used
if not re.match(r'[-dclpsbDCMnP?]([-r][-w][-xsS]){2}([-r][-w][-xtT])[+]?', linedata[0]) \
and linedata[0].endswith(':'):
parent = linedata.pop(0)[:-1]
# Pop following total line
linedata.pop(0)
# Look for parent line if glob or -R is used
if not re.match(r'[-dclpsbDCMnP?]([-r][-w][-xsS]){2}([-r][-w][-xtT])[+]?', linedata[0]) \
and linedata[0].endswith(':'):
parent = linedata.pop(0)[:-1]
# Pop following total line if it exists
if re.match(r'total [0-9]+', linedata[0]):
linedata.pop(0)
if linedata:
# Check if -l was used to parse extra data
if re.match(r'[-dclpsbDCMnP?]([-r][-w][-xsS]){2}([-r][-w][-xtT])[+]?', linedata[0]):
for entry in linedata:

View File

@@ -216,7 +216,7 @@ import jc.parsers.universal
class info():
version = '1.3'
version = '1.4'
description = 'lsblk command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -330,17 +330,20 @@ def parse(data, raw=False, quiet=False):
linedata = data.splitlines()
# Clear any blank lines
cleandata = list(filter(None, linedata))
cleandata = data.splitlines()
raw_output = []
cleandata[0] = cleandata[0].lower()
cleandata[0] = cleandata[0].replace(':', '_')
cleandata[0] = cleandata[0].replace('-', '_')
if cleandata:
cleandata = data.splitlines()
raw_output = jc.parsers.universal.sparse_table_parse(cleandata)
cleandata[0] = cleandata[0].lower()
cleandata[0] = cleandata[0].replace(':', '_')
cleandata[0] = cleandata[0].replace('-', '_')
# clean up non-ascii characters, if any
for entry in raw_output:
entry['name'] = entry['name'].encode('ascii', errors='ignore').decode()
raw_output = jc.parsers.universal.sparse_table_parse(cleandata)
# clean up non-ascii characters, if any
for entry in raw_output:
entry['name'] = entry['name'].encode('ascii', errors='ignore').decode()
if raw:
return raw_output

View File

@@ -107,7 +107,7 @@ import jc.parsers.universal
class info():
version = '1.1'
version = '1.2'
description = 'lsmod command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -175,13 +175,16 @@ def parse(data, raw=False, quiet=False):
jc.utils.compatibility(__name__, info.compatible)
cleandata = data.splitlines()
cleandata[0] = cleandata[0].lower()
raw_output = []
raw_output = jc.parsers.universal.simple_table_parse(cleandata)
if list(filter(None, cleandata)):
cleandata[0] = cleandata[0].lower()
for mod in raw_output:
if 'by' in mod:
mod['by'] = mod['by'].split(',')
raw_output = jc.parsers.universal.simple_table_parse(cleandata)
for mod in raw_output:
if 'by' in mod:
mod['by'] = mod['by'].split(',')
if raw:
return raw_output

View File

@@ -6,7 +6,7 @@ Usage:
Compatibility:
'linux', 'darwin'
'linux', 'darwin', 'freebsd'
Example:
@@ -56,13 +56,13 @@ import jc.utils
class info():
version = '1.2'
version = '1.4'
description = 'mount command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
compatible = ['linux', 'darwin']
compatible = ['linux', 'darwin', 'freebsd']
magic_commands = ['mount']
@@ -162,6 +162,7 @@ def parse(data, raw=False, quiet=False):
# Clear any blank lines
cleandata = list(filter(None, linedata))
raw_output = []
if cleandata:
# check for OSX output

View File

@@ -4,13 +4,18 @@ Usage:
Specify --netstat as the first argument if the piped input is coming from netstat
Caveats:
- Use of multiple 'l' options is not supported on OSX (e.g. 'netstat -rlll')
- Use of the 'A' option is not supported on OSX when using the 'r' option (e.g. netstat -rA)
Compatibility:
'linux'
'linux', 'darwin', 'freebsd'
Examples:
$ sudo netstat -apee | jc --netstat -p
# netstat -apee | jc --netstat -p
[
{
"proto": "tcp",
@@ -160,166 +165,95 @@ Examples:
...
]
$ sudo netstat -apee | jc --netstat -p -r
$ netstat -r | jc --netstat -p
[
{
"proto": "tcp",
"recv_q": "0",
"send_q": "0",
"local_address": "localhost",
"foreign_address": "0.0.0.0",
"state": "LISTEN",
"user": "systemd-resolve",
"inode": "26958",
"program_name": "systemd-resolve",
"kind": "network",
"pid": "887",
"local_port": "domain",
"foreign_port": "*",
"transport_protocol": "tcp",
"network_protocol": "ipv4"
"destination": "default",
"gateway": "gateway",
"genmask": "0.0.0.0",
"route_flags": "UG",
"mss": 0,
"window": 0,
"irtt": 0,
"iface": "ens33",
"kind": "route",
"route_flags_pretty": [
"UP",
"GATEWAY"
]
},
{
"proto": "tcp",
"recv_q": "0",
"send_q": "0",
"local_address": "0.0.0.0",
"foreign_address": "0.0.0.0",
"state": "LISTEN",
"user": "root",
"inode": "30499",
"program_name": "sshd",
"kind": "network",
"pid": "1186",
"local_port": "ssh",
"foreign_port": "*",
"transport_protocol": "tcp",
"network_protocol": "ipv4"
"destination": "172.17.0.0",
"gateway": "0.0.0.0",
"genmask": "255.255.0.0",
"route_flags": "U",
"mss": 0,
"window": 0,
"irtt": 0,
"iface": "docker0",
"kind": "route",
"route_flags_pretty": [
"UP"
]
},
{
"proto": "tcp",
"recv_q": "0",
"send_q": "0",
"local_address": "localhost",
"foreign_address": "localhost",
"state": "ESTABLISHED",
"user": "root",
"inode": "46829",
"program_name": "sshd: root",
"kind": "network",
"pid": "2242",
"local_port": "ssh",
"foreign_port": "52186",
"transport_protocol": "tcp",
"network_protocol": "ipv4"
"destination": "192.168.71.0",
"gateway": "0.0.0.0",
"genmask": "255.255.255.0",
"route_flags": "U",
"mss": 0,
"window": 0,
"irtt": 0,
"iface": "ens33",
"kind": "route",
"route_flags_pretty": [
"UP"
]
}
]
$ netstat -i | jc --netstat -p
[
{
"iface": "ens33",
"mtu": 1500,
"rx_ok": 476,
"rx_err": 0,
"rx_drp": 0,
"rx_ovr": 0,
"tx_ok": 312,
"tx_err": 0,
"tx_drp": 0,
"tx_ovr": 0,
"flg": "BMRU",
"kind": "interface"
},
{
"proto": "tcp",
"recv_q": "0",
"send_q": "0",
"local_address": "localhost",
"foreign_address": "localhost",
"state": "ESTABLISHED",
"user": "root",
"inode": "46828",
"program_name": "ssh",
"kind": "network",
"pid": "2241",
"local_port": "52186",
"foreign_port": "ssh",
"transport_protocol": "tcp",
"network_protocol": "ipv4"
},
{
"proto": "tcp6",
"recv_q": "0",
"send_q": "0",
"local_address": "[::]",
"foreign_address": "[::]",
"state": "LISTEN",
"user": "root",
"inode": "30510",
"program_name": "sshd",
"kind": "network",
"pid": "1186",
"local_port": "ssh",
"foreign_port": "*",
"transport_protocol": "tcp",
"network_protocol": "ipv6"
},
{
"proto": "udp",
"recv_q": "0",
"send_q": "0",
"local_address": "localhost",
"foreign_address": "0.0.0.0",
"state": null,
"user": "systemd-resolve",
"inode": "26957",
"program_name": "systemd-resolve",
"kind": "network",
"pid": "887",
"local_port": "domain",
"foreign_port": "*",
"transport_protocol": "udp",
"network_protocol": "ipv4"
},
{
"proto": "raw6",
"recv_q": "0",
"send_q": "0",
"local_address": "[::]",
"foreign_address": "[::]",
"state": "7",
"user": "systemd-network",
"inode": "27001",
"program_name": "systemd-network",
"kind": "network",
"pid": "867",
"local_port": "ipv6-icmp",
"foreign_port": "*",
"transport_protocol": null,
"network_protocol": "ipv6"
},
{
"proto": "unix",
"refcnt": "2",
"flags": null,
"type": "DGRAM",
"state": null,
"inode": "33322",
"program_name": "systemd",
"path": "/run/user/1000/systemd/notify",
"kind": "socket",
"pid": " 1607"
},
{
"proto": "unix",
"refcnt": "2",
"flags": "ACC",
"type": "SEQPACKET",
"state": "LISTENING",
"inode": "20835",
"program_name": "init",
"path": "/run/udev/control",
"kind": "socket",
"pid": " 1"
},
...
"iface": "lo",
"mtu": 65536,
"rx_ok": 0,
"rx_err": 0,
"rx_drp": 0,
"rx_ovr": 0,
"tx_ok": 0,
"tx_err": 0,
"tx_drp": 0,
"tx_ovr": 0,
"flg": "LRU",
"kind": "interface"
}
]
"""
import string
import jc.utils
class info():
version = '1.3'
version = '1.7'
description = 'netstat command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
compatible = ['linux']
compatible = ['linux', 'darwin', 'freebsd']
magic_commands = ['netstat']
@@ -340,34 +274,112 @@ def process(proc_data):
[
{
"proto": string,
"recv_q": integer,
"send_q": integer,
"transport_protocol" string,
"network_protocol": string,
"local_address": string,
"local_port": string,
"local_port_num": integer,
"foreign_address": string,
"foreign_port": string,
"foreign_port_num": integer,
"state": string,
"program_name": string,
"pid": integer,
"user": string,
"security_context": string,
"refcnt": integer,
"flags": string,
"type": string,
"inode": integer,
"path": string,
"kind": string
"proto": string,
"recv_q": integer,
"send_q": integer,
"transport_protocol" string,
"network_protocol": string,
"local_address": string,
"local_port": string,
"local_port_num": integer,
"foreign_address": string,
"foreign_port": string,
"foreign_port_num": integer,
"state": string,
"program_name": string,
"pid": integer,
"user": string,
"security_context": string,
"refcnt": integer,
"flags": string,
"type": string,
"inode": integer,
"path": string,
"kind": string,
"address": string,
"unix_inode": string,
"conn": string,
"refs": string,
"nextref": string,
"name": string,
"unit": integer,
"vendor": integer,
"class": integer,
"subcla": integer,
"unix_flags": integer,
"pcbcount": integer,
"rcvbuf": integer,
"sndbuf": integer,
"rxbytes": integer,
"txbytes": integer,
"destination": string,
"gateway": string,
"route_flags": string,
"route_flags_pretty": [
string,
]
"route_refs": integer,
"use": integer,
"mtu": integer,
"expire": string,
"genmask": string,
"mss": integer,
"window": integer,
"irtt": integer,
"iface": string,
"metric": integer,
"network": string,
"address": string,
"ipkts": integer, - = null
"ierrs": integer, - = null
"idrop": integer, - = null
"opkts": integer, - = null
"oerrs": integer, - = null
"coll": integer, - = null
"rx_ok": integer,
"rx_err": integer,
"rx_drp": integer,
"rx_ovr": integer,
"tx_ok": integer,
"tx_err": integer,
"tx_drp": integer,
"tx_ovr": integer,
"flg": string,
"ibytes": integer,
"obytes": integer,
"r_mbuf": integer,
"s_mbuf": integer,
"r_clus": integer,
"s_clus": integer,
"r_hiwa": integer,
"s_hiwa": integer,
"r_lowa": integer,
"s_lowa": integer,
"r_bcnt": integer,
"s_bcnt": integer,
"r_bmax": integer,
"s_bmax": integer,
"rexmit": integer,
"ooorcv": integer,
"0_win": integer,
"rexmt": float,
"persist": float,
"keep": float,
"2msl": float,
"delack": float,
"rcvtime": float,
}
]
"""
for entry in proc_data:
# integer changes
int_list = ['recv_q', 'send_q', 'pid', 'refcnt', 'inode']
int_list = ['recv_q', 'send_q', 'pid', 'refcnt', 'inode', 'unit', 'vendor', 'class',
'osx_flags', 'subcla', 'pcbcount', 'rcvbuf', 'sndbuf', 'rxbytes', 'txbytes',
'route_refs', 'use', 'mtu', 'mss', 'window', 'irtt', 'metric', 'ipkts',
'ierrs', 'opkts', 'oerrs', 'coll', 'rx_ok', 'rx_err', 'rx_drp', 'rx_ovr',
'tx_ok', 'tx_err', 'tx_drp', 'tx_ovr', 'idrop', 'ibytes', 'obytes', 'r_mbuf',
's_mbuf', 'r_clus', 's_clus', 'r_hiwa', 's_hiwa', 'r_lowa', 's_lowa', 'r_bcnt',
's_bcnt', 'r_bmax', 's_bmax', 'rexmit', 'ooorcv', '0_win']
for key in int_list:
if key in entry:
try:
@@ -376,6 +388,16 @@ def process(proc_data):
except (ValueError):
entry[key] = None
# float changes
float_list = ['rexmt', 'persist', 'keep', '2msl', 'delack', 'rcvtime']
for key in float_list:
if key in entry:
try:
key_float = float(entry[key])
entry[key] = key_float
except (ValueError):
entry[key] = None
if 'local_port' in entry:
try:
entry['local_port_num'] = int(entry['local_port'])
@@ -391,128 +413,6 @@ def process(proc_data):
return proc_data
def normalize_headers(header):
header = header.lower()
header = header.replace('local address', 'local_address')
header = header.replace('foreign address', 'foreign_address')
header = header.replace('pid/program name', 'program_name')
header = header.replace('security context', 'security_context')
header = header.replace('i-node', 'inode')
header = header.replace('-', '_')
return header
def parse_network(headers, entry):
# Count words in header
# if len of line is one less than len of header, then insert None in field 5
entry = entry.split(maxsplit=len(headers) - 1)
if len(entry) == len(headers) - 1:
entry.insert(5, None)
output_line = dict(zip(headers, entry))
output_line['kind'] = 'network'
return output_line
def parse_socket(header_text, headers, entry):
output_line = {}
# get the column # of first letter of "state"
state_col = header_text.find('state')
# get the program name column area
pn_start = header_text.find('program_name')
pn_end = header_text.find('path') - 1
# remove [ and ] from each line
entry = entry.replace('[ ]', '---')
entry = entry.replace('[', ' ').replace(']', ' ')
# find program_name column area and substitute spaces with \u2063 there
old_pn = entry[pn_start:pn_end]
new_pn = old_pn.replace(' ', '\u2063')
entry = entry.replace(old_pn, new_pn)
entry_list = entry.split(maxsplit=len(headers) - 1)
# check column # to see if state column is populated
if entry[state_col] in string.whitespace:
entry_list.insert(4, None)
output_line = dict(zip(headers, entry_list))
output_line['kind'] = 'socket'
# fix program_name field to turn \u2063 back to spaces
if 'program_name' in output_line:
if output_line['program_name']:
old_d_pn = output_line['program_name']
new_d_pn = old_d_pn.replace('\u2063', ' ')
output_line['program_name'] = new_d_pn
return output_line
def parse_post(raw_data):
# clean up trailing whitespace on each item in each entry
# flags --- = null
# program_name - = null
# split pid and program name and ip addresses and ports
# create network and transport protocol fields
for entry in raw_data:
for item in entry:
try:
entry[item] = entry[item].rstrip()
except (AttributeError):
# skips trying to rstrip Null entries
pass
if 'flags' in entry:
if entry['flags'] == '---':
entry['flags'] = None
if 'program_name' in entry:
entry['program_name'] = entry['program_name'].strip()
if entry['program_name'] == '-':
entry['program_name'] = None
if entry['program_name']:
pid = entry['program_name'].split('/', maxsplit=1)[0]
name = entry['program_name'].split('/', maxsplit=1)[1]
entry['pid'] = pid
entry['program_name'] = name
if 'local_address' in entry:
if entry['local_address']:
ladd = entry['local_address'].rsplit(':', maxsplit=1)[0]
lport = entry['local_address'].rsplit(':', maxsplit=1)[1]
entry['local_address'] = ladd
entry['local_port'] = lport
if 'foreign_address' in entry:
if entry['foreign_address']:
fadd = entry['foreign_address'].rsplit(':', maxsplit=1)[0]
fport = entry['foreign_address'].rsplit(':', maxsplit=1)[1]
entry['foreign_address'] = fadd
entry['foreign_port'] = fport
if 'proto' in entry and 'kind' in entry:
if entry['kind'] == 'network':
if 'tcp' in entry['proto']:
entry['transport_protocol'] = 'tcp'
elif 'udp' in entry['proto']:
entry['transport_protocol'] = 'udp'
else:
entry['transport_protocol'] = None
if '6' in entry['proto']:
entry['network_protocol'] = 'ipv6'
else:
entry['network_protocol'] = 'ipv4'
return raw_data
def parse(data, raw=False, quiet=False):
"""
Main text parsing function
@@ -527,51 +427,34 @@ def parse(data, raw=False, quiet=False):
List of dictionaries. Raw or processed structured data.
"""
import jc.utils
if not quiet:
jc.utils.compatibility(__name__, info.compatible)
cleandata = data.splitlines()
cleandata = list(filter(None, cleandata))
raw_output = []
network = False
socket = False
headers = ''
network_list = []
socket_list = []
for line in cleandata:
if cleandata:
# check for FreeBSD/OSX vs Linux
# is this from FreeBSD/OSX?
if cleandata[0] == 'Active Internet connections' \
or cleandata[0] == 'Active Internet connections (including servers)' \
or cleandata[0] == 'Active Multipath Internet connections' \
or cleandata[0] == 'Active LOCAL (UNIX) domain sockets' \
or cleandata[0] == 'Registered kernel control modules' \
or cleandata[0] == 'Active kernel event sockets' \
or cleandata[0] == 'Active kernel control sockets' \
or cleandata[0] == 'Routing tables' \
or cleandata[0].startswith('Name '):
if line.startswith('Active Internet'):
network_list = []
network = True
socket = False
continue
import jc.parsers.netstat_freebsd_osx
raw_output = jc.parsers.netstat_freebsd_osx.parse(cleandata)
if line.startswith('Active UNIX'):
socket_list = []
network = False
socket = True
continue
if line.startswith('Proto'):
header_text = normalize_headers(line)
headers = header_text.split()
continue
if network:
network_list.append(parse_network(headers, line))
continue
if socket:
socket_list.append(parse_socket(header_text, headers, line))
continue
for item in [network_list, socket_list]:
for entry in item:
raw_output.append(entry)
raw_output = parse_post(raw_output)
# use linux parser
else:
import jc.parsers.netstat_linux
raw_output = jc.parsers.netstat_linux.parse(cleandata)
if raw:
return raw_output

View File

@@ -0,0 +1,320 @@
"""jc - JSON CLI output utility FreeBSD and OSX netstat Parser"""
def normalize_headers(header):
header = header.lower()
header = header.replace('local address', 'local_address')
header = header.replace('foreign address', 'foreign_address')
header = header.replace('(state)', 'state')
header = header.replace('inode', 'unix_inode')
header = header.replace('flags', 'unix_flags')
header = header.replace('-', '_')
return header
def normalize_route_headers(header):
header = header.lower()
header = header.replace('flags', 'route_flags')
header = header.replace('refs', 'route_refs')
header = header.replace('netif', 'iface')
header = header.replace('-', '_')
return header
def normalize_interface_headers(header):
header = header.lower()
header = header.replace('name', 'iface')
header = header.replace('-', '_')
return header
def parse_item(headers, entry, kind):
entry = entry.split(maxsplit=len(headers) - 1)
# fixup udp records with no state field entry
if kind == 'network' and entry[0].startswith('udp'):
entry.insert(5, None)
if kind == 'network' and 'socket' in headers and 'udp' in str(entry):
entry.insert(7, None)
# fixup -T output on FreeBSD
if kind == 'network' and '0_win' in headers and entry[0].startswith('udp'):
entry.insert(1, '')
entry.insert(1, '')
entry.insert(1, '')
# fixup interface records with no address field entry
if kind == 'interface' and len(entry) == 8:
entry.insert(3, None)
output_line = dict(zip(headers, entry))
output_line['kind'] = kind
return output_line
def parse_post(raw_data):
for entry in raw_data:
# fixup name field in Registered kernel control module
if 'name' in entry:
if entry['name']:
entry['name'] = entry['name'].strip()
# create network and transport protocol fields
if 'local_address' in entry:
if entry['local_address']:
ladd = entry['local_address'].rsplit('.', maxsplit=1)[0]
lport = entry['local_address'].rsplit('.', maxsplit=1)[1]
entry['local_address'] = ladd
entry['local_port'] = lport
if 'foreign_address' in entry:
if entry['foreign_address']:
fadd = entry['foreign_address'].rsplit('.', maxsplit=1)[0]
fport = entry['foreign_address'].rsplit('.', maxsplit=1)[1]
entry['foreign_address'] = fadd
entry['foreign_port'] = fport
if 'proto' in entry and 'kind' in entry:
if entry['kind'] == 'network':
if entry['proto'] == 'udp46':
entry['transport_protocol'] = entry['proto'][:-2]
elif entry['proto'].startswith('icm'):
entry['transport_protocol'] = 'icmp'
else:
entry['transport_protocol'] = entry['proto'][:-1]
if '6' in entry['proto']:
entry['network_protocol'] = 'ipv6'
else:
entry['network_protocol'] = 'ipv4'
# add route_flags_pretty field
if 'route_flags' in entry:
flag_map = {
'1': 'PROTO1',
'2': 'PROTO2',
'3': 'PROTO3',
'B': 'BLACKHOLE',
'b': 'BROADCAST',
'C': 'CLONING',
'c': 'PRCLONING',
'D': 'DYNAMIC',
'G': 'GATEWAY',
'H': 'HOST',
'I': 'IFSCOPE',
'i': 'IFREF',
'L': 'LLINFO',
'M': 'MODIFIED',
'm': 'MULTICAST',
'R': 'REJECT',
'r': 'ROUTER',
'S': 'STATIC',
'U': 'UP',
'W': 'WASCLONED',
'X': 'XRESOLVE',
'Y': 'PROXY',
}
pretty_flags = []
for flag in entry['route_flags']:
if flag in flag_map:
pretty_flags.append(flag_map[flag])
entry['route_flags_pretty'] = pretty_flags
# strip whitespace from beginning and end of all string values
for item in entry:
if isinstance(entry[item], str):
entry[item] = entry[item].strip()
return raw_data
def parse(cleandata):
"""
Main text parsing function for OSX netstat
Parameters:
cleandata: (string) text data to parse
Returns:
List of dictionaries. Raw structured data.
"""
raw_output = []
network = False
multipath = False
socket = False
reg_kernel_control = False
active_kernel_event = False
active_kernel_control = False
routing_table = False
interface_table = False
for line in cleandata:
if line.startswith('Active Internet'):
network = True
multipath = False
socket = False
reg_kernel_control = False
active_kernel_event = False
active_kernel_control = False
routing_table = False
interface_table = False
continue
if line.startswith('Active Multipath Internet connections'):
network = False
multipath = True
socket = False
reg_kernel_control = False
active_kernel_event = False
active_kernel_control = False
routing_table = False
interface_table = False
continue
if line.startswith('Active LOCAL (UNIX) domain sockets') or line.startswith('Active UNIX domain sockets'):
network = False
multipath = False
socket = True
reg_kernel_control = False
active_kernel_event = False
active_kernel_control = False
routing_table = False
interface_table = False
continue
if line.startswith('Registered kernel control modules'):
network = False
multipath = False
socket = False
reg_kernel_control = True
active_kernel_event = False
active_kernel_control = False
routing_table = False
interface_table = False
continue
if line.startswith('Active kernel event sockets'):
network = False
multipath = False
socket = False
reg_kernel_control = False
active_kernel_event = True
active_kernel_control = False
routing_table = False
interface_table = False
continue
if line.startswith('Active kernel control sockets'):
network = False
multipath = False
socket = False
reg_kernel_control = False
active_kernel_event = False
active_kernel_control = True
routing_table = False
interface_table = False
continue
if line.startswith('Routing tables'):
network = False
multipath = False
socket = False
reg_kernel_control = False
active_kernel_event = False
active_kernel_control = False
routing_table = True
interface_table = False
continue
if line.startswith('Name '):
network = False
multipath = False
socket = False
reg_kernel_control = False
active_kernel_event = False
active_kernel_control = False
routing_table = False
interface_table = True
# don't continue since there is no real header row for this table
# get headers
if network and (line.startswith('Socket ') or line.startswith('Proto ') or line.startswith('Tcpcb ')):
header_text = normalize_headers(line)
headers = header_text.split()
continue
if socket and line.startswith('Address '):
header_text = normalize_headers(line)
headers = header_text.split()
continue
if reg_kernel_control and (line.startswith('id ') or line.startswith('kctlref ')):
header_text = normalize_headers(line)
headers = header_text.split()
continue
if active_kernel_event and (line.startswith('Proto ') or line.startswith(' pcb ')):
header_text = normalize_headers(line)
headers = header_text.split()
continue
if active_kernel_control and (line.startswith('Proto ') or line.startswith(' pcb ')):
header_text = normalize_headers(line)
headers = header_text.split()
continue
if routing_table and line.startswith('Destination '):
header_text = normalize_route_headers(line)
headers = header_text.split()
continue
if interface_table and line.startswith('Name '):
header_text = normalize_interface_headers(line)
headers = header_text.split()
continue
# get items
if network:
raw_output.append(parse_item(headers, line, 'network'))
continue
if multipath:
# not implemented
continue
if socket:
raw_output.append(parse_item(headers, line, 'socket'))
continue
if reg_kernel_control:
raw_output.append(parse_item(headers, line, 'Registered kernel control module'))
continue
if active_kernel_event:
raw_output.append(parse_item(headers, line, 'Active kernel event socket'))
continue
if active_kernel_control:
raw_output.append(parse_item(headers, line, 'Active kernel control socket'))
continue
if routing_table and not (line.startswith('Internet:') or line.startswith('Internet6:')):
raw_output.append(parse_item(headers, line, 'route'))
continue
if interface_table:
raw_output.append(parse_item(headers, line, 'interface'))
continue
return parse_post(raw_output)

280
jc/parsers/netstat_linux.py Normal file
View File

@@ -0,0 +1,280 @@
"""jc - JSON CLI output utility Linux netstat Parser"""
import string
def normalize_headers(header):
header = header.lower()
header = header.replace('local address', 'local_address')
header = header.replace('foreign address', 'foreign_address')
header = header.replace('pid/program name', 'program_name')
header = header.replace('security context', 'security_context')
header = header.replace('i-node', 'inode')
header = header.replace('-', '_')
return header
def normalize_route_headers(header):
header = header.lower()
header = header.replace('flags', 'route_flags')
header = header.replace('ref', 'route_refs')
header = header.replace('-', '_')
return header
def normalize_interface_headers(header):
header = header.lower()
header = header.replace('-', '_')
return header
def parse_network(headers, entry):
# Count words in header
# if len of line is one less than len of header, then insert None in field 5
entry = entry.split(maxsplit=len(headers) - 1)
if len(entry) == len(headers) - 1:
entry.insert(5, None)
output_line = dict(zip(headers, entry))
output_line['kind'] = 'network'
return output_line
def parse_socket(header_text, headers, entry):
# get the column # of first letter of "state"
state_col = header_text.find('state')
# get the program name column area
pn_start = header_text.find('program_name')
pn_end = header_text.find('path') - 1
# remove [ and ] from each line
entry = entry.replace('[ ]', '---')
entry = entry.replace('[', ' ').replace(']', ' ')
# find program_name column area and substitute spaces with \u2063 there
old_pn = entry[pn_start:pn_end]
new_pn = old_pn.replace(' ', '\u2063')
entry = entry.replace(old_pn, new_pn)
entry_list = entry.split(maxsplit=len(headers) - 1)
# check column # to see if state column is populated
if entry[state_col] in string.whitespace:
entry_list.insert(4, None)
output_line = dict(zip(headers, entry_list))
output_line['kind'] = 'socket'
# fix program_name field to turn \u2063 back to spaces
if 'program_name' in output_line:
if output_line['program_name']:
old_d_pn = output_line['program_name']
new_d_pn = old_d_pn.replace('\u2063', ' ')
output_line['program_name'] = new_d_pn
return output_line
def parse_route(headers, entry):
entry = entry.split(maxsplit=len(headers) - 1)
output_line = dict(zip(headers, entry))
output_line['kind'] = 'route'
return output_line
def parse_interface(headers, entry):
entry = entry.split(maxsplit=len(headers) - 1)
output_line = dict(zip(headers, entry))
output_line['kind'] = 'interface'
return output_line
def parse_post(raw_data):
# clean up trailing whitespace on each item in each entry
# flags --- = null
# program_name - = null
# split pid and program name and ip addresses and ports
# create network and transport protocol fields
for entry in raw_data:
for item in entry:
try:
entry[item] = entry[item].rstrip()
except (AttributeError):
# skips trying to rstrip Null entries
pass
if 'flags' in entry:
if entry['flags'] == '---':
entry['flags'] = None
if 'program_name' in entry:
entry['program_name'] = entry['program_name'].strip()
if entry['program_name'] == '-':
entry['program_name'] = None
if entry['program_name']:
pid = entry['program_name'].split('/', maxsplit=1)[0]
name = entry['program_name'].split('/', maxsplit=1)[1]
entry['pid'] = pid
entry['program_name'] = name
if 'local_address' in entry:
if entry['local_address']:
ladd = entry['local_address'].rsplit(':', maxsplit=1)[0]
lport = entry['local_address'].rsplit(':', maxsplit=1)[1]
entry['local_address'] = ladd
entry['local_port'] = lport
if 'foreign_address' in entry:
if entry['foreign_address']:
fadd = entry['foreign_address'].rsplit(':', maxsplit=1)[0]
fport = entry['foreign_address'].rsplit(':', maxsplit=1)[1]
entry['foreign_address'] = fadd
entry['foreign_port'] = fport
if 'proto' in entry and 'kind' in entry:
if entry['kind'] == 'network':
if 'tcp' in entry['proto']:
entry['transport_protocol'] = 'tcp'
elif 'udp' in entry['proto']:
entry['transport_protocol'] = 'udp'
else:
entry['transport_protocol'] = None
if '6' in entry['proto']:
entry['network_protocol'] = 'ipv6'
else:
entry['network_protocol'] = 'ipv4'
# add route_flags_pretty
# Flag mapping from https://www.man7.org/linux/man-pages/man8/route.8.html
if 'route_flags' in entry:
flag_map = {
'U': 'UP',
'H': 'HOST',
'G': 'GATEWAY',
'R': 'REINSTATE',
'D': 'DYNAMIC',
'M': 'MODIFIED',
'A': 'ADDRCONF',
'C': 'CACHE',
'!': 'REJECT'
}
pretty_flags = []
for flag in entry['route_flags']:
if flag in flag_map:
pretty_flags.append(flag_map[flag])
entry['route_flags_pretty'] = pretty_flags
return raw_data
def parse(cleandata):
"""
Main text parsing function for OSX netstat
Parameters:
cleandata: (string) text data to parse
Returns:
List of dictionaries. Raw structured data.
"""
raw_output = []
network = False
socket = False
bluetooth = False
routing_table = False
interface_table = False
headers = None
for line in cleandata:
if line.startswith('Active Internet'):
network = True
socket = False
bluetooth = False
routing_table = False
interface_table = False
continue
if line.startswith('Active UNIX'):
network = False
socket = True
bluetooth = False
routing_table = False
interface_table = False
continue
if line.startswith('Active Bluetooth'):
network = False
socket = False
bluetooth = True
routing_table = False
interface_table = False
continue
if line.startswith('Kernel IP routing table'):
network = False
socket = False
bluetooth = False
routing_table = True
interface_table = False
continue
if line.startswith('Kernel Interface table'):
network = False
socket = False
bluetooth = False
routing_table = False
interface_table = True
continue
# get headers
if line.startswith('Proto'):
header_text = normalize_headers(line)
headers = header_text.split()
continue
if line.startswith('Destination '):
header_text = normalize_route_headers(line)
headers = header_text.split()
continue
if line.startswith('Iface '):
header_text = normalize_interface_headers(line)
headers = header_text.split()
continue
# parse items
if network:
raw_output.append(parse_network(headers, line))
continue
if socket:
raw_output.append(parse_socket(header_text, headers, line))
continue
if bluetooth:
# not implemented
continue
if routing_table:
raw_output.append(parse_route(headers, line))
continue
if interface_table:
raw_output.append(parse_interface(headers, line))
continue
return parse_post(raw_output)

View File

@@ -6,7 +6,7 @@ Usage:
Compatibility:
'linux'
'linux', 'freebsd'
Examples:
@@ -183,13 +183,13 @@ import jc.parsers.universal
class info():
version = '1.0'
version = '1.2'
description = 'ntpq -p command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
compatible = ['linux']
compatible = ['linux', 'freebsd']
magic_commands = ['ntpq']
@@ -268,28 +268,29 @@ def parse(data, raw=False, quiet=False):
if not quiet:
jc.utils.compatibility(__name__, info.compatible)
cleandata = data.splitlines()
raw_output = []
cleandata = data.splitlines()
cleandata[0] = 's ' + cleandata[0]
cleandata[0] = cleandata[0].lower()
if list(filter(None, cleandata)):
cleandata[0] = 's ' + cleandata[0]
cleandata[0] = cleandata[0].lower()
# delete header delimiter
del cleandata[1]
# delete header delimiter
del cleandata[1]
# separate first character with a space for easier parsing
for i, line in list(enumerate(cleandata[1:])):
if line[0] == ' ':
# fixup for no-state
cleandata[i + 1] = '~ ' + line[1:]
else:
# fixup - realign columns since we added the 's' column
cleandata[i + 1] = line[:1] + ' ' + line[1:]
# separate first character with a space for easier parsing
for i, line in list(enumerate(cleandata[1:])):
if line[0] == ' ':
# fixup for no-state
cleandata[i + 1] = '~ ' + line[1:]
else:
# fixup - realign columns since we added the 's' column
cleandata[i + 1] = line[:1] + ' ' + line[1:]
# fixup for occaisional ip/hostname fields with a space
cleandata[i + 1] = cleandata[i + 1].replace(' (', '_(')
# fixup for occaisional ip/hostname fields with a space
cleandata[i + 1] = cleandata[i + 1].replace(' (', '_(')
raw_output = jc.parsers.universal.simple_table_parse(cleandata)
raw_output = jc.parsers.universal.simple_table_parse(cleandata)
if raw:
return raw_output

View File

@@ -32,7 +32,7 @@ import jc.parsers.universal
class info():
version = '1.1'
version = '1.2'
description = 'pip list command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -93,23 +93,24 @@ def parse(data, raw=False, quiet=False):
# Clear any blank lines
cleandata = list(filter(None, linedata))
# detect legacy output type
if ' (' in cleandata[0]:
for row in cleandata:
raw_output.append({'package': row.split(' (')[0],
'version': row.split(' (')[1].rstrip(')')})
if cleandata:
# detect legacy output type
if ' (' in cleandata[0]:
for row in cleandata:
raw_output.append({'package': row.split(' (')[0],
'version': row.split(' (')[1].rstrip(')')})
# otherwise normal table output
else:
# clear separator line
for i, line in reversed(list(enumerate(cleandata))):
if '---' in line:
cleandata.pop(i)
# otherwise normal table output
else:
# clear separator line
for i, line in reversed(list(enumerate(cleandata))):
if '---' in line:
cleandata.pop(i)
cleandata[0] = cleandata[0].lower()
cleandata[0] = cleandata[0].lower()
if cleandata:
raw_output = jc.parsers.universal.simple_table_parse(cleandata)
if cleandata:
raw_output = jc.parsers.universal.simple_table_parse(cleandata)
if raw:
return raw_output

View File

@@ -177,7 +177,7 @@ import jc.parsers.universal
class info():
version = '1.1'
version = '1.2'
description = 'ps command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -282,9 +282,12 @@ def parse(data, raw=False, quiet=False):
jc.utils.compatibility(__name__, info.compatible)
cleandata = data.splitlines()
cleandata[0] = cleandata[0].lower()
raw_output = []
raw_output = jc.parsers.universal.simple_table_parse(cleandata)
if list(filter(None, cleandata)):
cleandata[0] = cleandata[0].lower()
raw_output = jc.parsers.universal.simple_table_parse(cleandata)
if raw:
return raw_output

View File

@@ -14,53 +14,48 @@ Examples:
[
{
"destination": "default",
"gateway": "gateway",
"gateway": "_gateway",
"genmask": "0.0.0.0",
"flags": "UG",
"metric": 100,
"metric": 202,
"ref": 0,
"use": 0,
"iface": "ens33",
"mss": 0,
"window": 0,
"irtt": 0
},
{
"destination": "172.17.0.0",
"gateway": "0.0.0.0",
"genmask": "255.255.0.0",
"flags": "U",
"metric": 0,
"ref": 0,
"use": 0,
"iface": "docker",
"mss": 0,
"window": 0,
"irtt": 0
"irtt": 0,
"flags_pretty": [
"UP",
"GATEWAY"
]
},
{
"destination": "192.168.71.0",
"gateway": "0.0.0.0",
"genmask": "255.255.255.0",
"flags": "U",
"metric": 100,
"metric": 202,
"ref": 0,
"use": 0,
"iface": "ens33",
"mss": 0,
"window": 0,
"irtt": 0
"irtt": 0,
"flags_pretty": [
"UP"
]
}
]
$ route -ee | jc --route -p -r
[
{
"destination": "default",
"gateway": "gateway",
"gateway": "_gateway",
"genmask": "0.0.0.0",
"flags": "UG",
"metric": "100",
"metric": "202",
"ref": "0",
"use": "0",
"iface": "ens33",
@@ -68,25 +63,12 @@ Examples:
"window": "0",
"irtt": "0"
},
{
"destination": "172.17.0.0",
"gateway": "0.0.0.0",
"genmask": "255.255.0.0",
"flags": "U",
"metric": "0",
"ref": "0",
"use": "0",
"iface": "docker",
"mss": "0",
"window": "0",
"irtt": "0"
},
{
"destination": "192.168.71.0",
"gateway": "0.0.0.0",
"genmask": "255.255.255.0",
"flags": "U",
"metric": "100",
"metric": "202",
"ref": "0",
"use": "0",
"iface": "ens33",
@@ -95,13 +77,14 @@ Examples:
"irtt": "0"
}
]
"""
import jc.utils
import jc.parsers.universal
class info():
version = '1.0'
version = '1.2'
description = 'route command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -128,17 +111,20 @@ def process(proc_data):
[
{
"destination": string,
"gateway": string,
"genmask": string,
"flags": string,
"metric": integer,
"ref": integer,
"use": integer,
"mss": integer,
"window": integer,
"irtt": integer,
"iface": string
"destination": string,
"gateway": string,
"genmask": string,
"flags": string,
"flags_pretty": [
string,
]
"metric": integer,
"ref": integer,
"use": integer,
"mss": integer,
"window": integer,
"irtt": integer,
"iface": string
}
]
"""
@@ -152,6 +138,29 @@ def process(proc_data):
except (ValueError):
entry[key] = None
# add flags_pretty
# Flag mapping from https://www.man7.org/linux/man-pages/man8/route.8.html
if 'flags' in entry:
flag_map = {
'U': 'UP',
'H': 'HOST',
'G': 'GATEWAY',
'R': 'REINSTATE',
'D': 'DYNAMIC',
'M': 'MODIFIED',
'A': 'ADDRCONF',
'C': 'CACHE',
'!': 'REJECT'
}
pretty_flags = []
for flag in entry['flags']:
if flag in flag_map:
pretty_flags.append(flag_map[flag])
entry['flags_pretty'] = pretty_flags
return proc_data
@@ -173,9 +182,12 @@ def parse(data, raw=False, quiet=False):
jc.utils.compatibility(__name__, info.compatible)
cleandata = data.splitlines()[1:]
cleandata[0] = cleandata[0].lower()
raw_output = []
raw_output = jc.parsers.universal.simple_table_parse(cleandata)
if list(filter(None, cleandata)):
cleandata[0] = cleandata[0].lower()
raw_output = jc.parsers.universal.simple_table_parse(cleandata)
if raw:
return raw_output

View File

@@ -251,7 +251,7 @@ import jc.utils
class info():
version = '1.0'
version = '1.1'
description = 'ss command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -308,17 +308,17 @@ def process(proc_data):
except (ValueError):
entry[key] = None
if 'local_port' in entry:
if 'local_port' in entry:
try:
entry['local_port_num'] = int(entry['local_port'])
except (ValueError):
pass
if 'peer_port' in entry:
try:
entry['peer_port_num'] = int(entry['peer_port'])
except (ValueError):
pass
if 'peer_port' in entry:
try:
entry['peer_port_num'] = int(entry['peer_port'])
except (ValueError):
pass
return proc_data

View File

@@ -6,7 +6,7 @@ Usage:
Compatibility:
'linux'
'linux', 'darwin', 'freebsd'
Examples:
@@ -100,17 +100,18 @@ Examples:
..
]
"""
import shlex
import jc.utils
class info():
version = '1.1'
version = '1.4'
description = 'stat command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
compatible = ['linux']
compatible = ['linux', 'darwin', 'freebsd']
magic_commands = ['stat']
@@ -149,12 +150,16 @@ def process(proc_data):
"access_time": string, # - = null
"modify_time": string, # - = null
"change_time": string, # - = null
"birth_time": string # - = null
"birth_time": string, # - = null
"unix_device": integer,
"rdev": integer,
"block_size": integer,
"unix_flags": string
}
]
"""
for entry in proc_data:
int_list = ['size', 'blocks', 'io_blocks', 'inode', 'links', 'uid', 'gid']
int_list = ['size', 'blocks', 'io_blocks', 'inode', 'links', 'uid', 'gid', 'unix_device', 'rdev', 'block_size']
for key in int_list:
if key in entry:
try:
@@ -198,81 +203,109 @@ def parse(data, raw=False, quiet=False):
cleandata = list(filter(None, cleandata))
if cleandata:
# stats output contains 8 lines
for line in cleandata:
# line #1
if line.find('File:') == 2:
output_line = {}
line_list = line.split(maxsplit=1)
output_line['file'] = line_list[1]
# linux output
if cleandata[0].startswith(' File: '):
# stats output contains 8 lines
for line in cleandata:
# populate link_to field if -> found
if ' -> ' in output_line['file']:
filename = output_line['file'].split(' -> ')[0].strip('\u2018').rstrip('\u2019')
link = output_line['file'].split(' -> ')[1].strip('\u2018').rstrip('\u2019')
output_line['file'] = filename
output_line['link_to'] = link
else:
filename = output_line['file'].split(' -> ')[0].strip('\u2018').rstrip('\u2019')
output_line['file'] = filename
# line #1
if line.find('File:') == 2:
output_line = {}
line_list = line.split(maxsplit=1)
output_line['file'] = line_list[1]
continue
# populate link_to field if -> found
if ' -> ' in output_line['file']:
filename = output_line['file'].split(' -> ')[0].strip('\u2018').rstrip('\u2019')
link = output_line['file'].split(' -> ')[1].strip('\u2018').rstrip('\u2019')
output_line['file'] = filename
output_line['link_to'] = link
else:
filename = output_line['file'].split(' -> ')[0].strip('\u2018').rstrip('\u2019')
output_line['file'] = filename
# line #2
if line.find('Size:') == 2:
line_list = line.split(maxsplit=7)
output_line['size'] = line_list[1]
output_line['blocks'] = line_list[3]
output_line['io_blocks'] = line_list[6]
output_line['type'] = line_list[7]
continue
continue
# line #3
if line.startswith('Device:'):
line_list = line.split()
output_line['device'] = line_list[1]
output_line['inode'] = line_list[3]
output_line['links'] = line_list[5]
continue
# line #2
if line.find('Size:') == 2:
line_list = line.split(maxsplit=7)
output_line['size'] = line_list[1]
output_line['blocks'] = line_list[3]
output_line['io_blocks'] = line_list[6]
output_line['type'] = line_list[7]
continue
# line #4
if line.startswith('Access: ('):
line = line.replace('(', ' ').replace(')', ' ').replace('/', ' ')
line_list = line.split()
output_line['access'] = line_list[1]
output_line['flags'] = line_list[2]
output_line['uid'] = line_list[4]
output_line['user'] = line_list[5]
output_line['gid'] = line_list[7]
output_line['group'] = line_list[8]
continue
# line #3
if line.startswith('Device:'):
line_list = line.split()
output_line['device'] = line_list[1]
output_line['inode'] = line_list[3]
output_line['links'] = line_list[5]
continue
# line #5
if line.startswith('Access: 2'):
line_list = line.split(maxsplit=1)
output_line['access_time'] = line_list[1]
continue
# line #4
if line.startswith('Access: ('):
line = line.replace('(', ' ').replace(')', ' ').replace('/', ' ')
line_list = line.split()
output_line['access'] = line_list[1]
output_line['flags'] = line_list[2]
output_line['uid'] = line_list[4]
output_line['user'] = line_list[5]
output_line['gid'] = line_list[7]
output_line['group'] = line_list[8]
continue
# line #6
if line.startswith('Modify:'):
line_list = line.split(maxsplit=1)
output_line['modify_time'] = line_list[1]
continue
# line #5
if line.startswith('Access: 2'):
line_list = line.split(maxsplit=1)
output_line['access_time'] = line_list[1]
continue
# line #7
if line.startswith('Change:'):
line_list = line.split(maxsplit=1)
output_line['change_time'] = line_list[1]
continue
# line #6
if line.startswith('Modify:'):
line_list = line.split(maxsplit=1)
output_line['modify_time'] = line_list[1]
continue
# line #8
if line.find('Birth:') == 1:
line_list = line.split(maxsplit=1)
output_line['birth_time'] = line_list[1]
# line #7
if line.startswith('Change:'):
line_list = line.split(maxsplit=1)
output_line['change_time'] = line_list[1]
continue
# line #8
if line.find('Birth:') == 1:
line_list = line.split(maxsplit=1)
output_line['birth_time'] = line_list[1]
raw_output.append(output_line)
continue
# FreeBSD/OSX output
else:
for line in cleandata:
value = shlex.split(line)
output_line = {
'file': value[15],
'unix_device': value[0],
'inode': value[1],
'flags': value[2],
'links': value[3],
'user': value[4],
'group': value[5],
'rdev': value[6],
'size': value[7],
'access_time': value[8],
'modify_time': value[9],
'change_time': value[10],
'birth_time': value[11],
'block_size': value[12],
'blocks': value[13],
'unix_flags': value[14]
}
raw_output.append(output_line)
continue
if raw:
return raw_output

View File

@@ -40,7 +40,7 @@ import jc.utils
class info():
version = '1.1'
version = '1.2'
description = 'systemctl command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -99,24 +99,27 @@ def parse(data, raw=False, quiet=False):
linedata = data.splitlines()
# Clear any blank lines
linedata = list(filter(None, linedata))
# clean up non-ascii characters, if any
cleandata = []
for entry in linedata:
cleandata.append(entry.encode('ascii', errors='ignore').decode())
header_text = cleandata[0]
header_list = header_text.lower().split()
raw_output = []
for entry in cleandata[1:]:
if 'LOAD = ' in entry:
break
if linedata:
# clean up non-ascii characters, if any
cleandata = []
for entry in linedata:
cleandata.append(entry.encode('ascii', errors='ignore').decode())
else:
entry_list = entry.rstrip().split(maxsplit=4)
output_line = dict(zip(header_list, entry_list))
raw_output.append(output_line)
header_text = cleandata[0]
header_list = header_text.lower().split()
raw_output = []
for entry in cleandata[1:]:
if 'LOAD = ' in entry:
break
else:
entry_list = entry.rstrip().split(maxsplit=4)
output_line = dict(zip(header_list, entry_list))
raw_output.append(output_line)
if raw:
return raw_output

View File

@@ -59,7 +59,7 @@ import jc.utils
class info():
version = '1.1'
version = '1.2'
description = 'systemctl list-jobs command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -125,25 +125,29 @@ def parse(data, raw=False, quiet=False):
linedata = data.splitlines()
# Clear any blank lines
linedata = list(filter(None, linedata))
# clean up non-ascii characters, if any
cleandata = []
for entry in linedata:
cleandata.append(entry.encode('ascii', errors='ignore').decode())
header_text = cleandata[0]
header_text = header_text.lower()
header_list = header_text.split()
raw_output = []
for entry in cleandata[1:]:
if 'No jobs running.' in entry or 'jobs listed.' in entry:
break
if linedata:
cleandata = []
else:
entry_list = entry.split(maxsplit=4)
output_line = dict(zip(header_list, entry_list))
raw_output.append(output_line)
# clean up non-ascii characters, if any
for entry in linedata:
cleandata.append(entry.encode('ascii', errors='ignore').decode())
header_text = cleandata[0]
header_text = header_text.lower()
header_list = header_text.split()
raw_output = []
for entry in cleandata[1:]:
if 'No jobs running.' in entry or 'jobs listed.' in entry:
break
else:
entry_list = entry.split(maxsplit=4)
output_line = dict(zip(header_list, entry_list))
raw_output.append(output_line)
if raw:
return raw_output

View File

@@ -34,7 +34,7 @@ import jc.utils
class info():
version = '1.1'
version = '1.2'
description = 'systemctl list-sockets command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -91,24 +91,27 @@ def parse(data, raw=False, quiet=False):
linedata = data.splitlines()
# Clear any blank lines
linedata = list(filter(None, linedata))
# clean up non-ascii characters, if any
cleandata = []
for entry in linedata:
cleandata.append(entry.encode('ascii', errors='ignore').decode())
header_text = cleandata[0].lower()
header_list = header_text.split()
raw_output = []
for entry in cleandata[1:]:
if 'sockets listed.' in entry:
break
if linedata:
cleandata = []
# clean up non-ascii characters, if any
for entry in linedata:
cleandata.append(entry.encode('ascii', errors='ignore').decode())
else:
entry_list = entry.rsplit(maxsplit=2)
output_line = dict(zip(header_list, entry_list))
raw_output.append(output_line)
header_text = cleandata[0].lower()
header_list = header_text.split()
raw_output = []
for entry in cleandata[1:]:
if 'sockets listed.' in entry:
break
else:
entry_list = entry.rsplit(maxsplit=2)
output_line = dict(zip(header_list, entry_list))
raw_output.append(output_line)
if raw:
return raw_output

View File

@@ -31,7 +31,7 @@ import jc.utils
class info():
version = '1.1'
version = '1.2'
description = 'systemctl list-unit-files command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -87,25 +87,28 @@ def parse(data, raw=False, quiet=False):
linedata = data.splitlines()
# Clear any blank lines
linedata = list(filter(None, linedata))
# clean up non-ascii characters, if any
cleandata = []
for entry in linedata:
cleandata.append(entry.encode('ascii', errors='ignore').decode())
header_text = cleandata[0]
header_text = header_text.lower().replace('unit file', 'unit_file')
header_list = header_text.split()
raw_output = []
for entry in cleandata[1:]:
if 'unit files listed.' in entry:
break
if linedata:
cleandata = []
# clean up non-ascii characters, if any
for entry in linedata:
cleandata.append(entry.encode('ascii', errors='ignore').decode())
else:
entry_list = entry.split(maxsplit=4)
output_line = dict(zip(header_list, entry_list))
raw_output.append(output_line)
header_text = cleandata[0]
header_text = header_text.lower().replace('unit file', 'unit_file')
header_list = header_text.split()
raw_output = []
for entry in cleandata[1:]:
if 'unit files listed.' in entry:
break
else:
entry_list = entry.split(maxsplit=4)
output_line = dict(zip(header_list, entry_list))
raw_output.append(output_line)
if raw:
return raw_output

View File

@@ -10,7 +10,7 @@ Limitations:
Compatibility:
'linux', 'darwin'
'linux', 'darwin', 'freebsd'
Example:
@@ -30,13 +30,13 @@ import jc.utils
class info():
version = '1.1'
version = '1.2'
description = 'uname -a command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
compatible = ['linux', 'darwin']
compatible = ['linux', 'darwin', 'freebsd']
magic_commands = ['uname']

View File

@@ -34,7 +34,7 @@ import jc.utils
class info():
version = '1.0'
version = '1.1'
description = 'uptime command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -107,10 +107,9 @@ def parse(data, raw=False, quiet=False):
jc.utils.compatibility(__name__, info.compatible)
raw_output = {}
cleandata = data.splitlines()
if cleandata:
if list(filter(None, cleandata)):
parsed_line = cleandata[0].split()
# allow space for odd times

View File

@@ -83,7 +83,7 @@ import jc.utils
class info():
version = '1.0'
version = '1.2'
description = 'w command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -149,30 +149,39 @@ def parse(data, raw=False, quiet=False):
jc.utils.compatibility(__name__, info.compatible)
cleandata = data.splitlines()[1:]
header_text = cleandata[0].lower()
# fixup for 'from' column that can be blank
from_col = header_text.find('from')
# clean up 'login@' header
# even though @ in a key is valid json, it can make things difficult
header_text = header_text.replace('login@', 'login_at')
headers = [h for h in ' '.join(header_text.strip().split()).split() if h]
# parse lines
raw_output = []
if cleandata:
for entry in cleandata[1:]:
output_line = {}
# normalize data by inserting Null for missing data
temp_line = entry.split(maxsplit=len(headers) - 1)
if list(filter(None, cleandata)):
header_text = cleandata[0].lower()
# fixup for 'from' column that can be blank
from_col = header_text.find('from')
# clean up 'login@' header
# even though @ in a key is valid json, it can make things difficult
header_text = header_text.replace('login@', 'login_at')
headers = [h for h in ' '.join(header_text.strip().split()).split() if h]
# fix from column, always at column 2
if 'from' in headers:
if entry[from_col] in string.whitespace:
temp_line.insert(2, '-')
# parse lines
raw_output = []
if cleandata:
for entry in cleandata[1:]:
output_line = {}
output_line = dict(zip(headers, temp_line))
raw_output.append(output_line)
# normalize data by inserting Null for missing data
temp_line = entry.split(maxsplit=len(headers) - 1)
# fix from column, always at column 2
if 'from' in headers:
if entry[from_col] in string.whitespace:
temp_line.insert(2, '-')
output_line = dict(zip(headers, temp_line))
raw_output.append(output_line)
# strip whitespace from beginning and end of all string values
for row in raw_output:
for item in row:
if isinstance(row[item], str):
row[item] = row[item].strip()
if raw:
return raw_output

View File

@@ -59,7 +59,7 @@ import xmltodict
class info():
version = '1.0'
version = '1.1'
description = 'XML file parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -111,7 +111,9 @@ def parse(data, raw=False, quiet=False):
if not quiet:
jc.utils.compatibility(__name__, info.compatible)
if data:
raw_output = []
if list(filter(None, data.splitlines())):
raw_output = xmltodict.parse(data)
if raw:

View File

@@ -56,7 +56,14 @@ def compatibility(mod_name, compatible):
no return, just prints output to STDERR
"""
if sys.platform not in compatible:
platform_found = False
for platform in compatible:
if sys.platform.startswith(platform):
platform_found = True
break
if not platform_found:
mod = mod_name.split('.')[-1]
compat_list = ', '.join(compatible)
warning_message(f'{mod} parser not compatible with your OS ({sys.platform}).\n Compatible platforms: {compat_list}')

2
setup.cfg Normal file
View File

@@ -0,0 +1,2 @@
[metadata]
license_file = LICENSE.md

View File

@@ -5,10 +5,10 @@ with open('README.md', 'r') as f:
setuptools.setup(
name='jc',
version='1.10.7',
version='1.11.5',
author='Kelly Brazil',
author_email='kellyjonbrazil@gmail.com',
description='This tool serializes the output of popular command line tools and filetypes to structured JSON output.',
description='Converts the output of popular command-line tools and file-types to JSON.',
install_requires=[
'ruamel.yaml>=0.15.0',
'xmltodict>=0.12.0',
@@ -19,8 +19,7 @@ setuptools.setup(
long_description_content_type='text/markdown',
python_requires='>=3.6',
url='https://github.com/kellyjonbrazil/jc',
packages=setuptools.find_packages(),
include_package_data=True,
packages=setuptools.find_packages(exclude=['*.tests', '*.tests.*', 'tests.*', 'tests']),
entry_points={
'console_scripts': [
'jc=jc.cli:main'

File diff suppressed because one or more lines are too long

11810
tests/fixtures/centos-7.7/dmidecode.out vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1 +1 @@
[{"filename": "systemd-private-016de60725a3426792b93fc9f120b8f0-chronyd.service-oZqq4u", "parent": "."}, {"filename": "systemd-private-a30a5a178daa4042b42dfaf5ff9e5f68-chronyd.service-a1tpxv", "parent": "."}, {"filename": "systemd-private-af69d7360f3e40cfa947358c0fb5a6f8-chronyd.service-T3MQ4j", "parent": "."}, {"filename": "tmp.CvALl2jE6u", "parent": "."}, {"filename": "tmp.e7AlxSxY5a", "parent": "."}, {"filename": "tmp.uXm9yegjwj", "parent": "."}, {"filename": "a regular filename", "parent": "./lstest"}, {"filename": "this file has", "parent": "./lstest"}, {"filename": "a combination", "parent": "./lstest"}, {"filename": "of everything", "parent": "./lstest"}, {"filename": "this file has", "parent": "./lstest"}, {"filename": "a newline inside", "parent": "./lstest"}, {"filename": "this file has", "parent": "./lstest"}, {"filename": "four contiguous newlines inside", "parent": "./lstest"}, {"filename": "this file", "parent": "./lstest"}, {"filename": "has", "parent": "./lstest"}, {"filename": "six", "parent": "./lstest"}, {"filename": "newlines", "parent": "./lstest"}, {"filename": "within", "parent": "./lstest"}, {"filename": "this file starts with four newlines", "parent": "./lstest"}, {"filename": "this file starts with one newline", "parent": "./lstest"}]
[{"filename": "lstest", "parent": "."}, {"filename": "systemd-private-016de60725a3426792b93fc9f120b8f0-chronyd.service-oZqq4u", "parent": "."}, {"filename": "systemd-private-a30a5a178daa4042b42dfaf5ff9e5f68-chronyd.service-a1tpxv", "parent": "."}, {"filename": "systemd-private-af69d7360f3e40cfa947358c0fb5a6f8-chronyd.service-T3MQ4j", "parent": "."}, {"filename": "tmp.CvALl2jE6u", "parent": "."}, {"filename": "tmp.e7AlxSxY5a", "parent": "."}, {"filename": "tmp.uXm9yegjwj", "parent": "."}, {"filename": "a regular filename", "parent": "./lstest"}, {"filename": "this file has", "parent": "./lstest"}, {"filename": "a combination", "parent": "./lstest"}, {"filename": "of everything", "parent": "./lstest"}, {"filename": "this file has", "parent": "./lstest"}, {"filename": "a newline inside", "parent": "./lstest"}, {"filename": "this file has", "parent": "./lstest"}, {"filename": "four contiguous newlines inside", "parent": "./lstest"}, {"filename": "this file", "parent": "./lstest"}, {"filename": "has", "parent": "./lstest"}, {"filename": "six", "parent": "./lstest"}, {"filename": "newlines", "parent": "./lstest"}, {"filename": "within", "parent": "./lstest"}, {"filename": "this file starts with four newlines", "parent": "./lstest"}, {"filename": "this file starts with one newline", "parent": "./lstest"}]

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
[{"iface": "docker0", "mtu": 1500, "rx_ok": 0, "rx_err": 0, "rx_drp": 0, "rx_ovr": 0, "tx_ok": 0, "tx_err": 0, "tx_drp": 0, "tx_ovr": 0, "flg": "BMU", "kind": "interface"}, {"iface": "ens33", "mtu": 1500, "rx_ok": 476, "rx_err": 0, "rx_drp": 0, "rx_ovr": 0, "tx_ok": 312, "tx_err": 0, "tx_drp": 0, "tx_ovr": 0, "flg": "BMRU", "kind": "interface"}, {"iface": "lo", "mtu": 65536, "rx_ok": 0, "rx_err": 0, "rx_drp": 0, "rx_ovr": 0, "tx_ok": 0, "tx_err": 0, "tx_drp": 0, "tx_ovr": 0, "flg": "LRU", "kind": "interface"}]

View File

@@ -0,0 +1,5 @@
Kernel Interface table
Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
docker0 1500 0 0 0 0 0 0 0 0 BMU
ens33 1500 476 0 0 0 312 0 0 0 BMRU
lo 65536 0 0 0 0 0 0 0 0 LRU

View File

@@ -0,0 +1 @@
[{"destination": "default", "gateway": "gateway", "genmask": "0.0.0.0", "route_flags": "UG", "mss": 0, "window": 0, "irtt": 0, "iface": "ens33", "kind": "route", "route_flags_pretty": ["UP", "GATEWAY"]}, {"destination": "172.17.0.0", "gateway": "0.0.0.0", "genmask": "255.255.0.0", "route_flags": "U", "mss": 0, "window": 0, "irtt": 0, "iface": "docker0", "kind": "route", "route_flags_pretty": ["UP"]}, {"destination": "192.168.71.0", "gateway": "0.0.0.0", "genmask": "255.255.255.0", "route_flags": "U", "mss": 0, "window": 0, "irtt": 0, "iface": "ens33", "kind": "route", "route_flags_pretty": ["UP"]}]

View File

@@ -0,0 +1,5 @@
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
default gateway 0.0.0.0 UG 0 0 0 ens33
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
192.168.71.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33

View File

@@ -0,0 +1 @@
[{"destination": "0.0.0.0", "gateway": "192.168.71.2", "genmask": "0.0.0.0", "route_flags": "UG", "metric": 100, "route_refs": 0, "use": 0, "iface": "ens33", "kind": "route", "route_flags_pretty": ["UP", "GATEWAY"]}, {"destination": "172.17.0.0", "gateway": "0.0.0.0", "genmask": "255.255.0.0", "route_flags": "U", "metric": 0, "route_refs": 0, "use": 0, "iface": "docker0", "kind": "route", "route_flags_pretty": ["UP"]}, {"destination": "192.168.71.0", "gateway": "0.0.0.0", "genmask": "255.255.255.0", "route_flags": "U", "metric": 100, "route_refs": 0, "use": 0, "iface": "ens33", "kind": "route", "route_flags_pretty": ["UP"]}]

View File

@@ -0,0 +1,5 @@
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.71.2 0.0.0.0 UG 100 0 0 ens33
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
192.168.71.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33

View File

@@ -0,0 +1 @@
[{"destination": "0.0.0.0", "gateway": "192.168.71.2", "genmask": "0.0.0.0", "route_flags": "UG", "metric": 100, "route_refs": 0, "use": 0, "iface": "ens33", "mss": 0, "window": 0, "irtt": 0, "kind": "route", "route_flags_pretty": ["UP", "GATEWAY"]}, {"destination": "172.17.0.0", "gateway": "0.0.0.0", "genmask": "255.255.0.0", "route_flags": "U", "metric": 0, "route_refs": 0, "use": 0, "iface": "docker", "mss": 0, "window": 0, "irtt": 0, "kind": "route", "route_flags_pretty": ["UP"]}, {"destination": "192.168.71.0", "gateway": "0.0.0.0", "genmask": "255.255.255.0", "route_flags": "U", "metric": 100, "route_refs": 0, "use": 0, "iface": "ens33", "mss": 0, "window": 0, "irtt": 0, "kind": "route", "route_flags_pretty": ["UP"]}]

View File

@@ -0,0 +1,5 @@
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface MSS Window irtt
0.0.0.0 192.168.71.2 0.0.0.0 UG 100 0 0 ens33 0 0 0
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker 0 0 0
192.168.71.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33 0 0 0

View File

@@ -1 +1 @@
[{"destination": "0.0.0.0", "gateway": "192.168.71.2", "genmask": "0.0.0.0", "flags": "UG", "metric": 100, "ref": 0, "use": 0, "iface": "ens33"}, {"destination": "172.17.0.0", "gateway": "0.0.0.0", "genmask": "255.255.0.0", "flags": "U", "metric": 0, "ref": 0, "use": 0, "iface": "docker0"}, {"destination": "192.168.71.0", "gateway": "0.0.0.0", "genmask": "255.255.255.0", "flags": "U", "metric": 100, "ref": 0, "use": 0, "iface": "ens33"}]
[{"destination": "0.0.0.0", "gateway": "192.168.71.2", "genmask": "0.0.0.0", "flags": "UG", "metric": 100, "ref": 0, "use": 0, "iface": "ens33", "flags_pretty": ["UP", "GATEWAY"]}, {"destination": "172.17.0.0", "gateway": "0.0.0.0", "genmask": "255.255.0.0", "flags": "U", "metric": 0, "ref": 0, "use": 0, "iface": "docker0", "flags_pretty": ["UP"]}, {"destination": "192.168.71.0", "gateway": "0.0.0.0", "genmask": "255.255.255.0", "flags": "U", "metric": 100, "ref": 0, "use": 0, "iface": "ens33", "flags_pretty": ["UP"]}]

View File

@@ -1 +1 @@
[{"destination": "default", "gateway": "gateway", "genmask": "0.0.0.0", "flags": "UG", "metric": 100, "ref": 0, "use": 0, "iface": "ens33"}, {"destination": "172.17.0.0", "gateway": "0.0.0.0", "genmask": "255.255.0.0", "flags": "U", "metric": 0, "ref": 0, "use": 0, "iface": "docker0"}, {"destination": "192.168.71.0", "gateway": "0.0.0.0", "genmask": "255.255.255.0", "flags": "U", "metric": 100, "ref": 0, "use": 0, "iface": "ens33"}]
[{"destination": "default", "gateway": "gateway", "genmask": "0.0.0.0", "flags": "UG", "metric": 100, "ref": 0, "use": 0, "iface": "ens33", "flags_pretty": ["UP", "GATEWAY"]}, {"destination": "172.17.0.0", "gateway": "0.0.0.0", "genmask": "255.255.0.0", "flags": "U", "metric": 0, "ref": 0, "use": 0, "iface": "docker0", "flags_pretty": ["UP"]}, {"destination": "192.168.71.0", "gateway": "0.0.0.0", "genmask": "255.255.255.0", "flags": "U", "metric": 100, "ref": 0, "use": 0, "iface": "ens33", "flags_pretty": ["UP"]}]

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

11810
tests/fixtures/fedora32/dmidecode.out vendored Normal file

File diff suppressed because it is too large Load Diff

1
tests/fixtures/fedora32/last.json vendored Normal file
View File

@@ -0,0 +1 @@
[{"user": "kbrazil", "tty": "pts/0", "hostname": "192.168.71.1", "login": "Fri May 1 15:25", "logout": "gone - no logout"}, {"user": "kbrazil", "tty": "tty1", "hostname": null, "login": "Fri May 1 15:24", "logout": "gone - no logout"}, {"user": "reboot", "tty": "system boot", "hostname": "5.6.6-300.fc32.x", "login": "Fri May 1 15:24", "logout": "running"}, {"user": "kbrazil", "tty": "pts/0", "hostname": "192.168.71.1", "login": "Thu Apr 30 15:27", "logout": "15:22", "duration": "23:55"}, {"user": "kbrazil", "tty": "tty1", "hostname": null, "login": "Thu Apr 30 15:25", "logout": "down", "duration": "23:57"}, {"user": "reboot", "tty": "system boot", "hostname": "5.6.6-300.fc32.x", "login": "Thu Apr 30 15:22", "logout": "15:22", "duration": "1+00:00"}]

8
tests/fixtures/fedora32/last.out vendored Normal file
View File

@@ -0,0 +1,8 @@
kbrazil pts/0 192.168.71.1 Fri May 1 15:25 gone - no logout
kbrazil tty1 Fri May 1 15:24 gone - no logout
reboot system boot 5.6.6-300.fc32.x Fri May 1 15:24 still running
kbrazil pts/0 192.168.71.1 Thu Apr 30 15:27 - 15:22 (23:55)
kbrazil tty1 Thu Apr 30 15:25 - down (23:57)
reboot system boot 5.6.6-300.fc32.x Thu Apr 30 15:22 - 15:22 (1+00:00)
wtmp begins Thu Apr 30 15:22:02 2020

1
tests/fixtures/fedora32/netstat.json vendored Normal file

File diff suppressed because one or more lines are too long

139
tests/fixtures/fedora32/netstat.out vendored Normal file
View File

@@ -0,0 +1,139 @@
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 localhost.localdoma:ssh 192.168.71.1:52882 ESTABLISHED
udp 0 0 localhost.locald:bootpc 192.168.71.254:bootps ESTABLISHED
Active UNIX domain sockets (w/o servers)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ] DGRAM 36371 /run/user/1000/systemd/notify
unix 3 [ ] DGRAM 15453 /run/systemd/notify
unix 9 [ ] DGRAM 15471 /run/systemd/journal/dev-log
unix 2 [ ] DGRAM 165956 @userdb-9bf8f59ca8f2bcce47a377edbaf8985d
unix 12 [ ] DGRAM 15479 /run/systemd/journal/socket
unix 2 [ ] DGRAM 29064 /var/run/chrony/chronyd.sock
unix 2 [ ] DGRAM 165866 @userdb-3f208fa7c8c6d98822a696ee7ca5e3ad
unix 2 [ ] DGRAM 165863 @userdb-da253950013f5ea3bc51a4049480d04e
unix 2 [ ] DGRAM 165865
unix 3 [ ] STREAM CONNECTED 36476
unix 3 [ ] STREAM CONNECTED 31389
unix 3 [ ] STREAM CONNECTED 30999 /var/lib/sss/pipes/private/sbus-dp_implicit_files.692
unix 3 [ ] STREAM CONNECTED 33770 /run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 30731
unix 2 [ ] DGRAM 24653
unix 3 [ ] STREAM CONNECTED 31370 /var/lib/sss/pipes/private/sbus-dp_implicit_files.692
unix 2 [ ] DGRAM 165862
unix 2 [ ] DGRAM 33725
unix 3 [ ] STREAM CONNECTED 33885
unix 3 [ ] STREAM CONNECTED 31173
unix 3 [ ] STREAM CONNECTED 31019
unix 3 [ ] STREAM CONNECTED 33886
unix 3 [ ] STREAM CONNECTED 30735 /var/lib/sss/pipes/private/sbus-monitor
unix 3 [ ] STREAM CONNECTED 166231
unix 2 [ ] DGRAM 30987
unix 2 [ ] DGRAM 24745
unix 2 [ ] DGRAM 165955
unix 2 [ ] DGRAM 30575
unix 3 [ ] STREAM CONNECTED 31062 /run/dbus/system_bus_socket
unix 2 [ ] STREAM CONNECTED 35419
unix 3 [ ] STREAM CONNECTED 31399 /run/dbus/system_bus_socket
unix 2 [ ] DGRAM 32430
unix 2 [ ] DGRAM 29403
unix 3 [ ] STREAM CONNECTED 166232 /var/lib/sss/pipes/nss
unix 2 [ ] DGRAM 31127
unix 2 [ ] DGRAM 29538
unix 2 [ ] STREAM CONNECTED 33876
unix 3 [ ] STREAM CONNECTED 31020 /var/lib/sss/pipes/private/sbus-monitor
unix 3 [ ] STREAM CONNECTED 30998
unix 3 [ ] STREAM CONNECTED 36475
unix 2 [ ] DGRAM 36002
unix 3 [ ] STREAM CONNECTED 33769
unix 3 [ ] STREAM CONNECTED 31390 /var/lib/sss/pipes/private/sbus-monitor
unix 2 [ ] STREAM CONNECTED 33132
unix 3 [ ] STREAM CONNECTED 31398
unix 3 [ ] STREAM CONNECTED 30022
unix 3 [ ] DGRAM 24748
unix 3 [ ] DGRAM 24747
unix 2 [ ] DGRAM 36348
unix 2 [ ] DGRAM 32085
unix 3 [ ] STREAM CONNECTED 31168 /run/systemd/journal/stdout
unix 3 [ ] DGRAM 15455
unix 3 [ ] STREAM CONNECTED 30830
unix 3 [ ] STREAM CONNECTED 26911
unix 3 [ ] STREAM CONNECTED 35960
unix 2 [ ] DGRAM 24662
unix 2 [ ] STREAM CONNECTED 36345
unix 3 [ ] STREAM CONNECTED 32538
unix 3 [ ] STREAM CONNECTED 28747
unix 3 [ ] STREAM CONNECTED 31026
unix 3 [ ] DGRAM 28615
unix 3 [ ] STREAM CONNECTED 31713 /run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 31167
unix 3 [ ] STREAM CONNECTED 35989 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 36303 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 31809 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 29396 /run/systemd/journal/stdout
unix 2 [ ] STREAM CONNECTED 34911
unix 3 [ ] DGRAM 36374
unix 2 [ ] STREAM CONNECTED 32241
unix 3 [ ] STREAM CONNECTED 32057 /run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 32000 /run/systemd/journal/stdout
unix 2 [ ] DGRAM 33083
unix 3 [ ] STREAM CONNECTED 31017
unix 3 [ ] DGRAM 36373
unix 3 [ ] STREAM CONNECTED 34101
unix 3 [ ] STREAM CONNECTED 32539 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 26914
unix 3 [ ] STREAM CONNECTED 29395
unix 3 [ ] STREAM CONNECTED 31022
unix 3 [ ] DGRAM 15456
unix 3 [ ] STREAM CONNECTED 29251 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 26915
unix 2 [ ] STREAM CONNECTED 33052
unix 3 [ ] STREAM CONNECTED 31999
unix 2 [ ] DGRAM 29496
unix 3 [ ] STREAM CONNECTED 28400
unix 3 [ ] STREAM CONNECTED 36378 /run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 31808
unix 3 [ ] STREAM CONNECTED 29250
unix 3 [ ] STREAM CONNECTED 24582
unix 3 [ ] STREAM CONNECTED 32056
unix 3 [ ] STREAM CONNECTED 31347
unix 3 [ ] STREAM CONNECTED 28678 /run/systemd/journal/stdout
unix 2 [ ] DGRAM 30980
unix 3 [ ] STREAM CONNECTED 31348 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 28677
unix 3 [ ] STREAM CONNECTED 34102 /run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 24805 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 29322 /run/systemd/journal/stdout
unix 2 [ ] DGRAM 36357
unix 3 [ ] STREAM CONNECTED 30832 /run/systemd/journal/stdout
unix 2 [ ] DGRAM 26913
unix 2 [ ] STREAM CONNECTED 32010
unix 3 [ ] STREAM CONNECTED 28748 /run/systemd/journal/stdout
unix 2 [ ] DGRAM 28602
unix 3 [ ] STREAM CONNECTED 28401 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 31069 /run/dbus/system_bus_socket
unix 3 [ ] DGRAM 28616
unix 3 [ ] STREAM CONNECTED 32334 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 31712
unix 3 [ ] STREAM CONNECTED 36302
unix 3 [ ] STREAM CONNECTED 32333
unix 3 [ ] STREAM CONNECTED 32093
unix 3 [ ] STREAM CONNECTED 26912
unix 2 [ ] STREAM CONNECTED 35774
unix 3 [ ] STREAM CONNECTED 29321
unix 3 [ ] STREAM CONNECTED 31025
unix 3 [ ] STREAM CONNECTED 28470
unix 3 [ ] STREAM CONNECTED 32094 /run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 31259 /run/systemd/journal/stdout
unix 2 [ ] DGRAM 36471
unix 3 [ ] STREAM CONNECTED 31054
unix 3 [ ] STREAM CONNECTED 31064 /run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 28471 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 36377
unix 2 [ ] STREAM CONNECTED 35788
unix 3 [ ] STREAM CONNECTED 31258
unix 3 [ ] STREAM CONNECTED 31065 /run/dbus/system_bus_socket
Active Bluetooth connections (w/o servers)
Proto Destination Source State PSM DCID SCID IMTU OMTU Security
Proto Destination Source State Channel

1
tests/fixtures/freebsd12/arp-a.json vendored Normal file
View File

@@ -0,0 +1 @@
[{"name": null, "address": "192.168.71.163", "hwtype": "ethernet", "hwaddress": "00:0c:29:1a:4e:3b", "iface": "em0", "permanent": true}, {"name": null, "address": "192.168.71.2", "hwtype": "ethernet", "hwaddress": "00:50:56:f7:4a:fc", "iface": "em0", "permanent": false, "expires": 942}, {"name": null, "address": "192.168.71.1", "hwtype": "ethernet", "hwaddress": "00:50:56:c0:00:08", "iface": "em0", "permanent": false, "expires": 1182}]

3
tests/fixtures/freebsd12/arp-a.out vendored Normal file
View File

@@ -0,0 +1,3 @@
? (192.168.71.163) at 00:0c:29:1a:4e:3b on em0 permanent [ethernet]
? (192.168.71.2) at 00:50:56:f7:4a:fc on em0 expires in 942 seconds [ethernet]
? (192.168.71.1) at 00:50:56:c0:00:08 on em0 expires in 1182 seconds [ethernet]

1
tests/fixtures/freebsd12/last.json vendored Normal file
View File

@@ -0,0 +1 @@
[{"user": "kbrazil", "tty": "pts/0", "hostname": "192.168.71.1", "login": "Thu May 28 21:29", "logout": "still logged in"}, {"user": "kbrazil", "tty": "pts/0", "hostname": "192.168.71.1", "login": "Thu May 28 04:13", "logout": "21:29", "duration": "17:16"}, {"user": "kbrazil", "tty": "pts/0", "hostname": "192.168.71.1", "login": "Wed May 27 16:09", "logout": "04:13", "duration": "12:03"}, {"user": "root", "tty": "ttyv0", "hostname": null, "login": "Wed May 27 12:48", "logout": "still logged in"}, {"user": "kbrazil", "tty": "pts/0", "hostname": "192.168.71.1", "login": "Wed May 27 12:47", "logout": "16:09", "duration": "03:22"}, {"user": "kbrazil", "tty": "ttyv0", "hostname": null, "login": "Wed May 27 12:46", "logout": "12:48", "duration": "00:01"}, {"user": "boot time", "tty": null, "hostname": null, "login": "Wed May 27 12:46"}]

9
tests/fixtures/freebsd12/last.out vendored Normal file
View File

@@ -0,0 +1,9 @@
kbrazil pts/0 192.168.71.1 Thu May 28 21:29 still logged in
kbrazil pts/0 192.168.71.1 Thu May 28 04:13 - 21:29 (17:16)
kbrazil pts/0 192.168.71.1 Wed May 27 16:09 - 04:13 (12:03)
root ttyv0 Wed May 27 12:48 still logged in
kbrazil pts/0 192.168.71.1 Wed May 27 12:47 - 16:09 (03:22)
kbrazil ttyv0 Wed May 27 12:46 - 12:48 (00:01)
boot time Wed May 27 12:46
utx.log begins Wed May 27 12:46:05 PDT 2020

View File

@@ -0,0 +1 @@
[{"tcpcb": "fffff80003df43d0", "proto": "tcp4", "recv_q": 0, "send_q": 0, "local_address": "192.168.71.1", "foreign_address": "192.168.71.1", "state": "ESTABLISHED", "kind": "network", "local_port": "ssh", "foreign_port": "56321", "transport_protocol": "tcp", "network_protocol": "ipv4", "foreign_port_num": 56321}, {"tcpcb": "fffff80003df47a0", "proto": "tcp4", "recv_q": 0, "send_q": 0, "local_address": "localhost", "foreign_address": "*", "state": "LISTEN", "kind": "network", "local_port": "smtp", "foreign_port": "*", "transport_protocol": "tcp", "network_protocol": "ipv4"}, {"tcpcb": "fffff80003df4b70", "proto": "tcp4", "recv_q": 0, "send_q": 0, "local_address": "*", "foreign_address": "*", "state": "LISTEN", "kind": "network", "local_port": "ssh", "foreign_port": "*", "transport_protocol": "tcp", "network_protocol": "ipv4"}, {"tcpcb": "fffff80003df0000", "proto": "tcp6", "recv_q": 0, "send_q": 0, "local_address": "*", "foreign_address": "*", "state": "LISTEN", "kind": "network", "local_port": "ssh", "foreign_port": "*", "transport_protocol": "tcp", "network_protocol": "ipv6"}, {"tcpcb": "fffff80003ae81e8", "proto": "udp4", "recv_q": 0, "send_q": 0, "local_address": "*", "foreign_address": "*", "kind": "network", "local_port": "syslog", "foreign_port": "*", "transport_protocol": "udp", "network_protocol": "ipv4"}, {"tcpcb": "fffff80003ae87a0", "proto": "udp6", "recv_q": 0, "send_q": 0, "local_address": "*", "foreign_address": "*", "kind": "network", "local_port": "syslog", "foreign_port": "*", "transport_protocol": "udp", "network_protocol": "ipv6"}, {"address": "fffff80003ab6100", "type": "stream", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6200", "refs": "0", "nextref": "0", "kind": "socket"}, {"address": "fffff80003ab6200", "type": "stream", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6100", "refs": "0", "nextref": "0", "kind": "socket"}, {"address": "fffff80003ab6300", "type": "stream", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "0", "refs": "0", "nextref": "0", "kind": "socket"}, {"address": "fffff80003ab6800", "type": "stream", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6900", "refs": "0", "nextref": "0", "kind": "socket"}, {"address": "fffff80003ab6900", "type": "stream", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6800", "refs": "0", "nextref": "0", "kind": "socket"}, {"address": "fffff80003abf000", "type": "stream", "recv_q": 0, "send_q": 0, "unix_inode": "fffff80003c581e0", "conn": "0", "refs": "0", "nextref": "0", "addr": "/var/run/devd.pipe", "kind": "socket"}, {"address": "fffff80003ac3e00", "type": "dgram", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6c00", "refs": "0", "nextref": "fffff80003ab6400", "kind": "socket"}, {"address": "fffff80003ab6400", "type": "dgram", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6c00", "refs": "0", "nextref": "fffff80003ab6000", "kind": "socket"}, {"address": "fffff80003ab6000", "type": "dgram", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6c00", "refs": "0", "nextref": "fffff80003ab6600", "kind": "socket"}, {"address": "fffff80003ab6500", "type": "dgram", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6d00", "refs": "0", "nextref": "0", "kind": "socket"}, {"address": "fffff80003ab6600", "type": "dgram", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6c00", "refs": "0", "nextref": "0", "kind": "socket"}, {"address": "fffff80003ab6c00", "type": "dgram", "recv_q": 0, "send_q": 0, "unix_inode": "fffff80003c59d20", "conn": "0", "refs": "fffff80003ac3e00", "nextref": "0", "addr": "/var/run/logpriv", "kind": "socket"}, {"address": "fffff80003ab6d00", "type": "dgram", "recv_q": 0, "send_q": 0, "unix_inode": "fffff80003c67000", "conn": "0", "refs": "fffff80003ab6500", "nextref": "0", "addr": "/var/run/log", "kind": "socket"}, {"address": "fffff80003ab6e00", "type": "seqpac", "recv_q": 0, "send_q": 0, "unix_inode": "fffff80003c58000", "conn": "0", "refs": "0", "nextref": "0", "addr": "/var/run/devd.seqpacket.pipe", "kind": "socket"}]

24
tests/fixtures/freebsd12/netstat-Aa.out vendored Normal file
View File

@@ -0,0 +1,24 @@
Active Internet connections (including servers)
Tcpcb Proto Recv-Q Send-Q Local Address Foreign Address (state)
fffff80003df43d0 tcp4 0 0 192.168.71.1.ssh 192.168.71.1.56321 ESTABLISHED
fffff80003df47a0 tcp4 0 0 localhost.smtp *.* LISTEN
fffff80003df4b70 tcp4 0 0 *.ssh *.* LISTEN
fffff80003df0000 tcp6 0 0 *.ssh *.* LISTEN
fffff80003ae81e8 udp4 0 0 *.syslog *.*
fffff80003ae87a0 udp6 0 0 *.syslog *.*
Active UNIX domain sockets
Address Type Recv-Q Send-Q Inode Conn Refs Nextref Addr
fffff80003ab6100 stream 0 0 0 fffff80003ab6200 0 0
fffff80003ab6200 stream 0 0 0 fffff80003ab6100 0 0
fffff80003ab6300 stream 0 0 0 0 0 0
fffff80003ab6800 stream 0 0 0 fffff80003ab6900 0 0
fffff80003ab6900 stream 0 0 0 fffff80003ab6800 0 0
fffff80003abf000 stream 0 0 fffff80003c581e0 0 0 0 /var/run/devd.pipe
fffff80003ac3e00 dgram 0 0 0 fffff80003ab6c00 0 fffff80003ab6400
fffff80003ab6400 dgram 0 0 0 fffff80003ab6c00 0 fffff80003ab6000
fffff80003ab6000 dgram 0 0 0 fffff80003ab6c00 0 fffff80003ab6600
fffff80003ab6500 dgram 0 0 0 fffff80003ab6d00 0 0
fffff80003ab6600 dgram 0 0 0 fffff80003ab6c00 0 0
fffff80003ab6c00 dgram 0 0 fffff80003c59d20 0 fffff80003ac3e00 0 /var/run/logpriv
fffff80003ab6d00 dgram 0 0 fffff80003c67000 0 fffff80003ab6500 0 /var/run/log
fffff80003ab6e00 seqpac 0 0 fffff80003c58000 0 0 0 /var/run/devd.seqpacket.pipe

View File

@@ -0,0 +1 @@
[{"tcpcb": "fffff80003df43d0", "proto": "tcp4", "rexmit": 3, "ooorcv": 0, "0_win": 0, "local_address": "192.168.71.1", "foreign_address": "192.168.71.1", "kind": "network", "local_port": "ssh", "foreign_port": "64330", "transport_protocol": "tcp", "network_protocol": "ipv4", "foreign_port_num": 64330}, {"tcpcb": "fffff80003df47a0", "proto": "tcp4", "rexmit": 0, "ooorcv": 0, "0_win": 0, "local_address": "localhost", "foreign_address": "*", "kind": "network", "local_port": "smtp", "foreign_port": "*", "transport_protocol": "tcp", "network_protocol": "ipv4"}, {"tcpcb": "fffff80003df4b70", "proto": "tcp4", "rexmit": 0, "ooorcv": 0, "0_win": 0, "local_address": "*", "foreign_address": "*", "kind": "network", "local_port": "ssh", "foreign_port": "*", "transport_protocol": "tcp", "network_protocol": "ipv4"}, {"tcpcb": "fffff80003df0000", "proto": "tcp6", "rexmit": 0, "ooorcv": 0, "0_win": 0, "local_address": "*", "foreign_address": "*", "kind": "network", "local_port": "ssh", "foreign_port": "*", "transport_protocol": "tcp", "network_protocol": "ipv6"}, {"tcpcb": "fffff80003ae81e8", "proto": "udp4", "rexmit": null, "ooorcv": null, "kind": "network", "transport_protocol": "udp", "network_protocol": "ipv4"}, {"tcpcb": "fffff80003ae87a0", "proto": "udp6", "rexmit": null, "ooorcv": null, "kind": "network", "transport_protocol": "udp", "network_protocol": "ipv6"}, {"address": "fffff80003ab6200", "type": "stream", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6100", "refs": "0", "nextref": "0", "kind": "socket"}, {"address": "fffff80003ab6100", "type": "stream", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6200", "refs": "0", "nextref": "0", "kind": "socket"}, {"address": "fffff80003ab6300", "type": "stream", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "0", "refs": "0", "nextref": "0", "kind": "socket"}, {"address": "fffff80003ab6800", "type": "stream", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6900", "refs": "0", "nextref": "0", "kind": "socket"}, {"address": "fffff80003ab6900", "type": "stream", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6800", "refs": "0", "nextref": "0", "kind": "socket"}, {"address": "fffff80003abf000", "type": "stream", "recv_q": 0, "send_q": 0, "unix_inode": "fffff80003c581e0", "conn": "0", "refs": "0", "nextref": "0", "addr": "/var/run/devd.pipe", "kind": "socket"}, {"address": "fffff80003ac3e00", "type": "dgram", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6c00", "refs": "0", "nextref": "fffff80003ab6400", "kind": "socket"}, {"address": "fffff80003ab6400", "type": "dgram", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6c00", "refs": "0", "nextref": "fffff80003ab6000", "kind": "socket"}, {"address": "fffff80003ab6000", "type": "dgram", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6c00", "refs": "0", "nextref": "fffff80003ab6600", "kind": "socket"}, {"address": "fffff80003ab6500", "type": "dgram", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6d00", "refs": "0", "nextref": "0", "kind": "socket"}, {"address": "fffff80003ab6600", "type": "dgram", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6c00", "refs": "0", "nextref": "0", "kind": "socket"}, {"address": "fffff80003ab6c00", "type": "dgram", "recv_q": 0, "send_q": 0, "unix_inode": "fffff80003c59d20", "conn": "0", "refs": "fffff80003ac3e00", "nextref": "0", "addr": "/var/run/logpriv", "kind": "socket"}, {"address": "fffff80003ab6d00", "type": "dgram", "recv_q": 0, "send_q": 0, "unix_inode": "fffff80003c67000", "conn": "0", "refs": "fffff80003ab6500", "nextref": "0", "addr": "/var/run/log", "kind": "socket"}, {"address": "fffff80003ab6e00", "type": "seqpac", "recv_q": 0, "send_q": 0, "unix_inode": "fffff80003c58000", "conn": "0", "refs": "0", "nextref": "0", "addr": "/var/run/devd.seqpacket.pipe", "kind": "socket"}]

View File

@@ -0,0 +1,24 @@
Active Internet connections (including servers)
Tcpcb Proto Rexmit OOORcv 0-win Local Address Foreign Address
fffff80003df43d0 tcp4 3 0 0 192.168.71.1.ssh 192.168.71.1.64330
fffff80003df47a0 tcp4 0 0 0 localhost.smtp *.*
fffff80003df4b70 tcp4 0 0 0 *.ssh *.*
fffff80003df0000 tcp6 0 0 0 *.ssh *.*
fffff80003ae81e8 udp4 *.syslog *.*
fffff80003ae87a0 udp6 *.syslog *.*
Active UNIX domain sockets
Address Type Recv-Q Send-Q Inode Conn Refs Nextref Addr
fffff80003ab6200 stream 0 0 0 fffff80003ab6100 0 0
fffff80003ab6100 stream 0 0 0 fffff80003ab6200 0 0
fffff80003ab6300 stream 0 0 0 0 0 0
fffff80003ab6800 stream 0 0 0 fffff80003ab6900 0 0
fffff80003ab6900 stream 0 0 0 fffff80003ab6800 0 0
fffff80003abf000 stream 0 0 fffff80003c581e0 0 0 0 /var/run/devd.pipe
fffff80003ac3e00 dgram 0 0 0 fffff80003ab6c00 0 fffff80003ab6400
fffff80003ab6400 dgram 0 0 0 fffff80003ab6c00 0 fffff80003ab6000
fffff80003ab6000 dgram 0 0 0 fffff80003ab6c00 0 fffff80003ab6600
fffff80003ab6500 dgram 0 0 0 fffff80003ab6d00 0 0
fffff80003ab6600 dgram 0 0 0 fffff80003ab6c00 0 0
fffff80003ab6c00 dgram 0 0 fffff80003c59d20 0 fffff80003ac3e00 0 /var/run/logpriv
fffff80003ab6d00 dgram 0 0 fffff80003c67000 0 fffff80003ab6500 0 /var/run/log
fffff80003ab6e00 seqpac 0 0 fffff80003c58000 0 0 0 /var/run/devd.seqpacket.pipe

View File

@@ -0,0 +1 @@
[{"tcpcb": "fffff80003df43d0", "proto": "tcp4", "recv_q": 0, "send_q": 0, "local_address": "192.168.71.163", "foreign_address": "192.168.71.1", "state": "ESTABLISHED", "log": "-", "kind": "network", "local_port": "22", "foreign_port": "64330", "transport_protocol": "tcp", "network_protocol": "ipv4", "local_port_num": 22, "foreign_port_num": 64330}, {"tcpcb": "fffff80003df47a0", "proto": "tcp4", "recv_q": 0, "send_q": 0, "local_address": "127.0.0.1", "foreign_address": "*", "state": "LISTEN", "log": "-", "kind": "network", "local_port": "25", "foreign_port": "*", "transport_protocol": "tcp", "network_protocol": "ipv4", "local_port_num": 25}, {"tcpcb": "fffff80003df4b70", "proto": "tcp4", "recv_q": 0, "send_q": 0, "local_address": "*", "foreign_address": "*", "state": "LISTEN", "log": "-", "kind": "network", "local_port": "22", "foreign_port": "*", "transport_protocol": "tcp", "network_protocol": "ipv4", "local_port_num": 22}, {"tcpcb": "fffff80003df0000", "proto": "tcp6", "recv_q": 0, "send_q": 0, "local_address": "*", "foreign_address": "*", "state": "LISTEN", "log": "-", "kind": "network", "local_port": "22", "foreign_port": "*", "transport_protocol": "tcp", "network_protocol": "ipv6", "local_port_num": 22}, {"tcpcb": "fffff80003ae81e8", "proto": "udp4", "recv_q": 0, "send_q": 0, "local_address": "*", "foreign_address": "*", "kind": "network", "local_port": "514", "foreign_port": "*", "transport_protocol": "udp", "network_protocol": "ipv4", "local_port_num": 514}, {"tcpcb": "fffff80003ae87a0", "proto": "udp6", "recv_q": 0, "send_q": 0, "local_address": "*", "foreign_address": "*", "kind": "network", "local_port": "514", "foreign_port": "*", "transport_protocol": "udp", "network_protocol": "ipv6", "local_port_num": 514}, {"address": "fffff80003ab6200", "type": "stream", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6100", "refs": "0", "nextref": "0", "kind": "socket"}, {"address": "fffff80003ab6100", "type": "stream", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6200", "refs": "0", "nextref": "0", "kind": "socket"}, {"address": "fffff80003ab6300", "type": "stream", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "0", "refs": "0", "nextref": "0", "kind": "socket"}, {"address": "fffff80003ab6800", "type": "stream", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6900", "refs": "0", "nextref": "0", "kind": "socket"}, {"address": "fffff80003ab6900", "type": "stream", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6800", "refs": "0", "nextref": "0", "kind": "socket"}, {"address": "fffff80003abf000", "type": "stream", "recv_q": 0, "send_q": 0, "unix_inode": "fffff80003c581e0", "conn": "0", "refs": "0", "nextref": "0", "addr": "/var/run/devd.pipe", "kind": "socket"}, {"address": "fffff80003ac3e00", "type": "dgram", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6c00", "refs": "0", "nextref": "fffff80003ab6400", "kind": "socket"}, {"address": "fffff80003ab6400", "type": "dgram", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6c00", "refs": "0", "nextref": "fffff80003ab6000", "kind": "socket"}, {"address": "fffff80003ab6000", "type": "dgram", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6c00", "refs": "0", "nextref": "fffff80003ab6600", "kind": "socket"}, {"address": "fffff80003ab6500", "type": "dgram", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6d00", "refs": "0", "nextref": "0", "kind": "socket"}, {"address": "fffff80003ab6600", "type": "dgram", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6c00", "refs": "0", "nextref": "0", "kind": "socket"}, {"address": "fffff80003ab6c00", "type": "dgram", "recv_q": 0, "send_q": 0, "unix_inode": "fffff80003c59d20", "conn": "0", "refs": "fffff80003ac3e00", "nextref": "0", "addr": "/var/run/logpriv", "kind": "socket"}, {"address": "fffff80003ab6d00", "type": "dgram", "recv_q": 0, "send_q": 0, "unix_inode": "fffff80003c67000", "conn": "0", "refs": "fffff80003ab6500", "nextref": "0", "addr": "/var/run/log", "kind": "socket"}, {"address": "fffff80003ab6e00", "type": "seqpac", "recv_q": 0, "send_q": 0, "unix_inode": "fffff80003c58000", "conn": "0", "refs": "0", "nextref": "0", "addr": "/var/run/devd.seqpacket.pipe", "kind": "socket"}]

View File

@@ -0,0 +1,24 @@
Active Internet connections (including servers)
Tcpcb Proto Recv-Q Send-Q Local Address Foreign Address (state) Log ID
fffff80003df43d0 tcp4 0 0 192.168.71.163.22 192.168.71.1.64330 ESTABLISHED -
fffff80003df47a0 tcp4 0 0 127.0.0.1.25 *.* LISTEN -
fffff80003df4b70 tcp4 0 0 *.22 *.* LISTEN -
fffff80003df0000 tcp6 0 0 *.22 *.* LISTEN -
fffff80003ae81e8 udp4 0 0 *.514 *.*
fffff80003ae87a0 udp6 0 0 *.514 *.*
Active UNIX domain sockets
Address Type Recv-Q Send-Q Inode Conn Refs Nextref Addr
fffff80003ab6200 stream 0 0 0 fffff80003ab6100 0 0
fffff80003ab6100 stream 0 0 0 fffff80003ab6200 0 0
fffff80003ab6300 stream 0 0 0 0 0 0
fffff80003ab6800 stream 0 0 0 fffff80003ab6900 0 0
fffff80003ab6900 stream 0 0 0 fffff80003ab6800 0 0
fffff80003abf000 stream 0 0 fffff80003c581e0 0 0 0 /var/run/devd.pipe
fffff80003ac3e00 dgram 0 0 0 fffff80003ab6c00 0 fffff80003ab6400
fffff80003ab6400 dgram 0 0 0 fffff80003ab6c00 0 fffff80003ab6000
fffff80003ab6000 dgram 0 0 0 fffff80003ab6c00 0 fffff80003ab6600
fffff80003ab6500 dgram 0 0 0 fffff80003ab6d00 0 0
fffff80003ab6600 dgram 0 0 0 fffff80003ab6c00 0 0
fffff80003ab6c00 dgram 0 0 fffff80003c59d20 0 fffff80003ac3e00 0 /var/run/logpriv
fffff80003ab6d00 dgram 0 0 fffff80003c67000 0 fffff80003ab6500 0 /var/run/log
fffff80003ab6e00 seqpac 0 0 fffff80003c58000 0 0 0 /var/run/devd.seqpacket.pipe

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,24 @@
Active Internet connections (including servers)
Tcpcb Proto Recv-Q Send-Q Local Address Foreign Address R-MBUF S-MBUF R-CLUS S-CLUS R-HIWA S-HIWA R-LOWA S-LOWA R-BCNT S-BCNT R-BMAX S-BMAX rexmt persist keep 2msl delack rcvtime
fffff80003df43d0 tcp4 0 0 192.168.71.1.ssh 192.168.71.1.64330 0 0 0 0 65700 33580 1 2048 0 0 525600 268640 0.00 0.00 5079.93 0.00 0.00 0.00
fffff80003df47a0 tcp4 0 0 localhost.smtp *.* 0 0 0 0 0 0 0 0 0 0 0 0 0.00 0.00 0.00 0.00 0.00 8841.63
fffff80003df4b70 tcp4 0 0 *.ssh *.* 0 0 0 0 0 0 0 0 0 0 0 0 0.00 0.00 0.00 0.00 0.00 8857.24
fffff80003df0000 tcp6 0 0 *.ssh *.* 0 0 0 0 0 0 0 0 0 0 0 0 0.00 0.00 0.00 0.00 0.00 8857.24
fffff80003ae81e8 udp4 0 0 *.syslog *.* 0 0 0 0 0 9216 0 2048 0 0 0 73728
fffff80003ae87a0 udp6 0 0 *.syslog *.* 0 0 0 0 0 9216 0 2048 0 0 0 73728
Active UNIX domain sockets
Address Type Recv-Q Send-Q Inode Conn Refs Nextref Addr
fffff80003ab6200 stream 0 0 0 fffff80003ab6100 0 0
fffff80003ab6100 stream 0 0 0 fffff80003ab6200 0 0
fffff80003ab6300 stream 0 0 0 0 0 0
fffff80003ab6800 stream 0 0 0 fffff80003ab6900 0 0
fffff80003ab6900 stream 0 0 0 fffff80003ab6800 0 0
fffff80003abf000 stream 0 0 fffff80003c581e0 0 0 0 /var/run/devd.pipe
fffff80003ac3e00 dgram 0 0 0 fffff80003ab6c00 0 fffff80003ab6400
fffff80003ab6400 dgram 0 0 0 fffff80003ab6c00 0 fffff80003ab6000
fffff80003ab6000 dgram 0 0 0 fffff80003ab6c00 0 fffff80003ab6600
fffff80003ab6500 dgram 0 0 0 fffff80003ab6d00 0 0
fffff80003ab6600 dgram 0 0 0 fffff80003ab6c00 0 0
fffff80003ab6c00 dgram 0 0 fffff80003c59d20 0 fffff80003ac3e00 0 /var/run/logpriv
fffff80003ab6d00 dgram 0 0 fffff80003c67000 0 fffff80003ab6500 0 /var/run/log
fffff80003ab6e00 seqpac 0 0 fffff80003c58000 0 0 0 /var/run/devd.seqpacket.pipe

View File

@@ -0,0 +1 @@
[{"proto": "tcp4", "rexmit": 3, "ooorcv": 0, "0_win": 0, "local_address": "192.168.71.163", "foreign_address": "192.168.71.1", "kind": "network", "local_port": "ssh", "foreign_port": "64330", "transport_protocol": "tcp", "network_protocol": "ipv4", "foreign_port_num": 64330}, {"proto": "tcp4", "rexmit": 0, "ooorcv": 0, "0_win": 0, "local_address": "localhost", "foreign_address": "*", "kind": "network", "local_port": "smtp", "foreign_port": "*", "transport_protocol": "tcp", "network_protocol": "ipv4"}, {"proto": "tcp4", "rexmit": 0, "ooorcv": 0, "0_win": 0, "local_address": "*", "foreign_address": "*", "kind": "network", "local_port": "ssh", "foreign_port": "*", "transport_protocol": "tcp", "network_protocol": "ipv4"}, {"proto": "tcp6", "rexmit": 0, "ooorcv": 0, "0_win": 0, "local_address": "*", "foreign_address": "*", "kind": "network", "local_port": "ssh", "foreign_port": "*", "transport_protocol": "tcp", "network_protocol": "ipv6"}, {"proto": "udp4", "rexmit": null, "ooorcv": null, "0_win": null, "local_address": "*", "foreign_address": "*", "kind": "network", "local_port": "syslog", "foreign_port": "*", "transport_protocol": "udp", "network_protocol": "ipv4"}, {"proto": "udp6", "rexmit": null, "ooorcv": null, "0_win": null, "local_address": "*", "foreign_address": "*", "kind": "network", "local_port": "syslog", "foreign_port": "*", "transport_protocol": "udp", "network_protocol": "ipv6"}, {"address": "fffff80003ab6200", "type": "stream", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6100", "refs": "0", "nextref": "0", "kind": "socket"}, {"address": "fffff80003ab6100", "type": "stream", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6200", "refs": "0", "nextref": "0", "kind": "socket"}, {"address": "fffff80003ab6300", "type": "stream", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "0", "refs": "0", "nextref": "0", "kind": "socket"}, {"address": "fffff80003ab6800", "type": "stream", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6900", "refs": "0", "nextref": "0", "kind": "socket"}, {"address": "fffff80003ab6900", "type": "stream", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6800", "refs": "0", "nextref": "0", "kind": "socket"}, {"address": "fffff80003abf000", "type": "stream", "recv_q": 0, "send_q": 0, "unix_inode": "fffff80003c581e0", "conn": "0", "refs": "0", "nextref": "0", "addr": "/var/run/devd.pipe", "kind": "socket"}, {"address": "fffff80003ac3e00", "type": "dgram", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6c00", "refs": "0", "nextref": "fffff80003ab6400", "kind": "socket"}, {"address": "fffff80003ab6400", "type": "dgram", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6c00", "refs": "0", "nextref": "fffff80003ab6000", "kind": "socket"}, {"address": "fffff80003ab6000", "type": "dgram", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6c00", "refs": "0", "nextref": "fffff80003ab6600", "kind": "socket"}, {"address": "fffff80003ab6500", "type": "dgram", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6d00", "refs": "0", "nextref": "0", "kind": "socket"}, {"address": "fffff80003ab6600", "type": "dgram", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6c00", "refs": "0", "nextref": "0", "kind": "socket"}, {"address": "fffff80003ab6c00", "type": "dgram", "recv_q": 0, "send_q": 0, "unix_inode": "fffff80003c59d20", "conn": "0", "refs": "fffff80003ac3e00", "nextref": "0", "addr": "/var/run/logpriv", "kind": "socket"}, {"address": "fffff80003ab6d00", "type": "dgram", "recv_q": 0, "send_q": 0, "unix_inode": "fffff80003c67000", "conn": "0", "refs": "fffff80003ab6500", "nextref": "0", "addr": "/var/run/log", "kind": "socket"}, {"address": "fffff80003ab6e00", "type": "seqpac", "recv_q": 0, "send_q": 0, "unix_inode": "fffff80003c58000", "conn": "0", "refs": "0", "nextref": "0", "addr": "/var/run/devd.seqpacket.pipe", "kind": "socket"}]

24
tests/fixtures/freebsd12/netstat-aT.out vendored Normal file
View File

@@ -0,0 +1,24 @@
Active Internet connections (including servers)
Proto Rexmit OOORcv 0-win Local Address Foreign Address
tcp4 3 0 0 192.168.71.163.ssh 192.168.71.1.64330
tcp4 0 0 0 localhost.smtp *.*
tcp4 0 0 0 *.ssh *.*
tcp6 0 0 0 *.ssh *.*
udp4 *.syslog *.*
udp6 *.syslog *.*
Active UNIX domain sockets
Address Type Recv-Q Send-Q Inode Conn Refs Nextref Addr
fffff80003ab6200 stream 0 0 0 fffff80003ab6100 0 0
fffff80003ab6100 stream 0 0 0 fffff80003ab6200 0 0
fffff80003ab6300 stream 0 0 0 0 0 0
fffff80003ab6800 stream 0 0 0 fffff80003ab6900 0 0
fffff80003ab6900 stream 0 0 0 fffff80003ab6800 0 0
fffff80003abf000 stream 0 0 fffff80003c581e0 0 0 0 /var/run/devd.pipe
fffff80003ac3e00 dgram 0 0 0 fffff80003ab6c00 0 fffff80003ab6400
fffff80003ab6400 dgram 0 0 0 fffff80003ab6c00 0 fffff80003ab6000
fffff80003ab6000 dgram 0 0 0 fffff80003ab6c00 0 fffff80003ab6600
fffff80003ab6500 dgram 0 0 0 fffff80003ab6d00 0 0
fffff80003ab6600 dgram 0 0 0 fffff80003ab6c00 0 0
fffff80003ab6c00 dgram 0 0 fffff80003c59d20 0 fffff80003ac3e00 0 /var/run/logpriv
fffff80003ab6d00 dgram 0 0 fffff80003c67000 0 fffff80003ab6500 0 /var/run/log
fffff80003ab6e00 seqpac 0 0 fffff80003c58000 0 0 0 /var/run/devd.seqpacket.pipe

View File

@@ -0,0 +1 @@
[{"proto": "tcp4", "recv_q": 0, "send_q": 0, "local_address": "192.168.71.163", "foreign_address": "192.168.71.1", "state": "ESTABLISHED", "kind": "network", "local_port": "22", "foreign_port": "56321", "transport_protocol": "tcp", "network_protocol": "ipv4", "local_port_num": 22, "foreign_port_num": 56321}, {"proto": "tcp4", "recv_q": 0, "send_q": 0, "local_address": "127.0.0.1", "foreign_address": "*", "state": "LISTEN", "kind": "network", "local_port": "25", "foreign_port": "*", "transport_protocol": "tcp", "network_protocol": "ipv4", "local_port_num": 25}, {"proto": "tcp4", "recv_q": 0, "send_q": 0, "local_address": "*", "foreign_address": "*", "state": "LISTEN", "kind": "network", "local_port": "22", "foreign_port": "*", "transport_protocol": "tcp", "network_protocol": "ipv4", "local_port_num": 22}, {"proto": "tcp6", "recv_q": 0, "send_q": 0, "local_address": "*", "foreign_address": "*", "state": "LISTEN", "kind": "network", "local_port": "22", "foreign_port": "*", "transport_protocol": "tcp", "network_protocol": "ipv6", "local_port_num": 22}, {"proto": "udp4", "recv_q": 0, "send_q": 0, "local_address": "*", "foreign_address": "*", "state": null, "kind": "network", "local_port": "514", "foreign_port": "*", "transport_protocol": "udp", "network_protocol": "ipv4", "local_port_num": 514}, {"proto": "udp6", "recv_q": 0, "send_q": 0, "local_address": "*", "foreign_address": "*", "state": null, "kind": "network", "local_port": "514", "foreign_port": "*", "transport_protocol": "udp", "network_protocol": "ipv6", "local_port_num": 514}, {"address": "fffff80003ab6100", "type": "stream", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6200", "refs": "0", "nextref": "0", "kind": "socket"}, {"address": "fffff80003ab6200", "type": "stream", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6100", "refs": "0", "nextref": "0", "kind": "socket"}, {"address": "fffff80003ab6300", "type": "stream", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "0", "refs": "0", "nextref": "0", "kind": "socket"}, {"address": "fffff80003ab6800", "type": "stream", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6900", "refs": "0", "nextref": "0", "kind": "socket"}, {"address": "fffff80003ab6900", "type": "stream", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6800", "refs": "0", "nextref": "0", "kind": "socket"}, {"address": "fffff80003abf000", "type": "stream", "recv_q": 0, "send_q": 0, "unix_inode": "fffff80003c581e0", "conn": "0", "refs": "0", "nextref": "0", "addr": "/var/run/devd.pipe", "kind": "socket"}, {"address": "fffff80003ac3e00", "type": "dgram", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6c00", "refs": "0", "nextref": "fffff80003ab6400", "kind": "socket"}, {"address": "fffff80003ab6400", "type": "dgram", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6c00", "refs": "0", "nextref": "fffff80003ab6000", "kind": "socket"}, {"address": "fffff80003ab6000", "type": "dgram", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6c00", "refs": "0", "nextref": "fffff80003ab6600", "kind": "socket"}, {"address": "fffff80003ab6500", "type": "dgram", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6d00", "refs": "0", "nextref": "0", "kind": "socket"}, {"address": "fffff80003ab6600", "type": "dgram", "recv_q": 0, "send_q": 0, "unix_inode": "0", "conn": "fffff80003ab6c00", "refs": "0", "nextref": "0", "kind": "socket"}, {"address": "fffff80003ab6c00", "type": "dgram", "recv_q": 0, "send_q": 0, "unix_inode": "fffff80003c59d20", "conn": "0", "refs": "fffff80003ac3e00", "nextref": "0", "addr": "/var/run/logpriv", "kind": "socket"}, {"address": "fffff80003ab6d00", "type": "dgram", "recv_q": 0, "send_q": 0, "unix_inode": "fffff80003c67000", "conn": "0", "refs": "fffff80003ab6500", "nextref": "0", "addr": "/var/run/log", "kind": "socket"}, {"address": "fffff80003ab6e00", "type": "seqpac", "recv_q": 0, "send_q": 0, "unix_inode": "fffff80003c58000", "conn": "0", "refs": "0", "nextref": "0", "addr": "/var/run/devd.seqpacket.pipe", "kind": "socket"}]

24
tests/fixtures/freebsd12/netstat-an.out vendored Normal file
View File

@@ -0,0 +1,24 @@
Active Internet connections (including servers)
Proto Recv-Q Send-Q Local Address Foreign Address (state)
tcp4 0 0 192.168.71.163.22 192.168.71.1.56321 ESTABLISHED
tcp4 0 0 127.0.0.1.25 *.* LISTEN
tcp4 0 0 *.22 *.* LISTEN
tcp6 0 0 *.22 *.* LISTEN
udp4 0 0 *.514 *.*
udp6 0 0 *.514 *.*
Active UNIX domain sockets
Address Type Recv-Q Send-Q Inode Conn Refs Nextref Addr
fffff80003ab6100 stream 0 0 0 fffff80003ab6200 0 0
fffff80003ab6200 stream 0 0 0 fffff80003ab6100 0 0
fffff80003ab6300 stream 0 0 0 0 0 0
fffff80003ab6800 stream 0 0 0 fffff80003ab6900 0 0
fffff80003ab6900 stream 0 0 0 fffff80003ab6800 0 0
fffff80003abf000 stream 0 0 fffff80003c581e0 0 0 0 /var/run/devd.pipe
fffff80003ac3e00 dgram 0 0 0 fffff80003ab6c00 0 fffff80003ab6400
fffff80003ab6400 dgram 0 0 0 fffff80003ab6c00 0 fffff80003ab6000
fffff80003ab6000 dgram 0 0 0 fffff80003ab6c00 0 fffff80003ab6600
fffff80003ab6500 dgram 0 0 0 fffff80003ab6d00 0 0
fffff80003ab6600 dgram 0 0 0 fffff80003ab6c00 0 0
fffff80003ab6c00 dgram 0 0 fffff80003c59d20 0 fffff80003ac3e00 0 /var/run/logpriv
fffff80003ab6d00 dgram 0 0 fffff80003c67000 0 fffff80003ab6500 0 /var/run/log
fffff80003ab6e00 seqpac 0 0 fffff80003c58000 0 0 0 /var/run/devd.seqpacket.pipe

View File

@@ -0,0 +1 @@
[{"iface": "em0", "mtu": 1500, "network": "<Link#1>", "address": "00:0c:29:1a:4e:3b", "ipkts": 189449, "ierrs": 0, "idrop": 0, "opkts": 211310, "oerrs": 0, "coll": 0, "kind": "interface"}, {"iface": "em0", "mtu": null, "network": "fe80::%em0/64", "address": "fe80::20c:29ff:fe", "ipkts": 0, "ierrs": null, "idrop": null, "opkts": 4, "oerrs": null, "coll": null, "kind": "interface"}, {"iface": "em0", "mtu": null, "network": "192.168.71.0/", "address": "192.168.71.163", "ipkts": 92481, "ierrs": null, "idrop": null, "opkts": 172946, "oerrs": null, "coll": null, "kind": "interface"}, {"iface": "lo0", "mtu": 16384, "network": "<Link#2>", "address": "lo0", "ipkts": 26, "ierrs": 0, "idrop": 0, "opkts": 26, "oerrs": 0, "coll": 0, "kind": "interface"}, {"iface": "lo0", "mtu": null, "network": "localhost", "address": "localhost", "ipkts": 23, "ierrs": null, "idrop": null, "opkts": 23, "oerrs": null, "coll": null, "kind": "interface"}, {"iface": "lo0", "mtu": null, "network": "fe80::%lo0/64", "address": "fe80::1%lo0", "ipkts": 0, "ierrs": null, "idrop": null, "opkts": 0, "oerrs": null, "coll": null, "kind": "interface"}, {"iface": "lo0", "mtu": null, "network": "your-net", "address": "localhost", "ipkts": 3, "ierrs": null, "idrop": null, "opkts": 3, "oerrs": null, "coll": null, "kind": "interface"}]

View File

@@ -0,0 +1,8 @@
Name Mtu Network Address Ipkts Ierrs Idrop Opkts Oerrs Coll
em0 1500 <Link#1> 00:0c:29:1a:4e:3b 189449 0 0 211310 0 0
em0 - fe80::%em0/64 fe80::20c:29ff:fe 0 - - 4 - -
em0 - 192.168.71.0/ 192.168.71.163 92481 - - 172946 - -
lo0 16384 <Link#2> lo0 26 0 0 26 0 0
lo0 - localhost localhost 23 - - 23 - -
lo0 - fe80::%lo0/64 fe80::1%lo0 0 - - 0 - -
lo0 - your-net localhost 3 - - 3 - -

View File

@@ -0,0 +1 @@
[{"iface": "em0", "mtu": 1500, "network": "<Link#1>", "address": "00:0c:29:1a:4e:3b", "ipkts": 372717, "ierrs": 0, "idrop": 0, "ibytes": 372538087, "opkts": 213821, "oerrs": 0, "obytes": 198573339, "coll": 0, "kind": "interface"}, {"iface": "em0", "mtu": null, "network": "fe80::%em0/64", "address": "fe80::20c:29ff:fe", "ipkts": 0, "ierrs": null, "idrop": null, "ibytes": 0, "opkts": 4, "oerrs": null, "obytes": 264, "coll": null, "kind": "interface"}, {"iface": "em0", "mtu": null, "network": "192.168.71.0/", "address": "192.168.71.163", "ipkts": 97396, "ierrs": null, "idrop": null, "ibytes": 68178099, "opkts": 175413, "oerrs": null, "obytes": 193957797, "coll": null, "kind": "interface"}, {"iface": "lo0", "mtu": 16384, "network": "<Link#2>", "address": "lo0", "ipkts": 98, "ierrs": 0, "idrop": 0, "ibytes": 21024, "opkts": 98, "oerrs": 0, "obytes": 21024, "coll": 0, "kind": "interface"}, {"iface": "lo0", "mtu": null, "network": "localhost", "address": "localhost", "ipkts": 25, "ierrs": null, "idrop": null, "ibytes": 4829, "opkts": 25, "oerrs": null, "obytes": 4829, "coll": null, "kind": "interface"}, {"iface": "lo0", "mtu": null, "network": "fe80::%lo0/64", "address": "fe80::1%lo0", "ipkts": 0, "ierrs": null, "idrop": null, "ibytes": 0, "opkts": 0, "oerrs": null, "obytes": 0, "coll": null, "kind": "interface"}, {"iface": "lo0", "mtu": null, "network": "your-net", "address": "localhost", "ipkts": 73, "ierrs": null, "idrop": null, "ibytes": 16195, "opkts": 73, "oerrs": null, "obytes": 16195, "coll": null, "kind": "interface"}]

View File

@@ -0,0 +1,8 @@
Name Mtu Network Address Ipkts Ierrs Idrop Ibytes Opkts Oerrs Obytes Coll
em0 1500 <Link#1> 00:0c:29:1a:4e:3b 372717 0 0 372538087 213821 0 198573339 0
em0 - fe80::%em0/64 fe80::20c:29ff:fe 0 - - 0 4 - 264 -
em0 - 192.168.71.0/ 192.168.71.163 97396 - - 68178099 175413 - 193957797 -
lo0 16384 <Link#2> lo0 98 0 0 21024 98 0 21024 0
lo0 - localhost localhost 25 - - 4829 25 - 4829 -
lo0 - fe80::%lo0/64 fe80::1%lo0 0 - - 0 0 - 0 -
lo0 - your-net localhost 73 - - 16195 73 - 16195 -

View File

@@ -0,0 +1 @@
[{"destination": "default", "gateway": "192.168.71.2", "route_flags": "UGS", "iface": "em0", "kind": "route", "route_flags_pretty": ["UP", "GATEWAY", "STATIC"]}, {"destination": "localhost", "gateway": "link#2", "route_flags": "UH", "iface": "lo0", "kind": "route", "route_flags_pretty": ["UP", "HOST"]}, {"destination": "192.168.71.0/24", "gateway": "link#1", "route_flags": "U", "iface": "em0", "kind": "route", "route_flags_pretty": ["UP"]}, {"destination": "192.168.71.163", "gateway": "link#1", "route_flags": "UHS", "iface": "lo0", "kind": "route", "route_flags_pretty": ["UP", "HOST", "STATIC"]}, {"destination": "::/96", "gateway": "localhost", "route_flags": "UGRS", "iface": "lo0", "kind": "route", "route_flags_pretty": ["UP", "GATEWAY", "REJECT", "STATIC"]}, {"destination": "localhost", "gateway": "link#2", "route_flags": "UH", "iface": "lo0", "kind": "route", "route_flags_pretty": ["UP", "HOST"]}, {"destination": "::ffff:0.0.0.0/96", "gateway": "localhost", "route_flags": "UGRS", "iface": "lo0", "kind": "route", "route_flags_pretty": ["UP", "GATEWAY", "REJECT", "STATIC"]}, {"destination": "fe80::/10", "gateway": "localhost", "route_flags": "UGRS", "iface": "lo0", "kind": "route", "route_flags_pretty": ["UP", "GATEWAY", "REJECT", "STATIC"]}, {"destination": "fe80::%em0/64", "gateway": "link#1", "route_flags": "U", "iface": "em0", "kind": "route", "route_flags_pretty": ["UP"]}, {"destination": "fe80::20c:29ff:fe1", "gateway": "link#1", "route_flags": "UHS", "iface": "lo0", "kind": "route", "route_flags_pretty": ["UP", "HOST", "STATIC"]}, {"destination": "fe80::%lo0/64", "gateway": "link#2", "route_flags": "U", "iface": "lo0", "kind": "route", "route_flags_pretty": ["UP"]}, {"destination": "fe80::1%lo0", "gateway": "link#2", "route_flags": "UHS", "iface": "lo0", "kind": "route", "route_flags_pretty": ["UP", "HOST", "STATIC"]}, {"destination": "ff02::/16", "gateway": "localhost", "route_flags": "UGRS", "iface": "lo0", "kind": "route", "route_flags_pretty": ["UP", "GATEWAY", "REJECT", "STATIC"]}]

20
tests/fixtures/freebsd12/netstat-r.out vendored Normal file
View File

@@ -0,0 +1,20 @@
Routing tables
Internet:
Destination Gateway Flags Netif Expire
default 192.168.71.2 UGS em0
localhost link#2 UH lo0
192.168.71.0/24 link#1 U em0
192.168.71.163 link#1 UHS lo0
Internet6:
Destination Gateway Flags Netif Expire
::/96 localhost UGRS lo0
localhost link#2 UH lo0
::ffff:0.0.0.0/96 localhost UGRS lo0
fe80::/10 localhost UGRS lo0
fe80::%em0/64 link#1 U em0
fe80::20c:29ff:fe1 link#1 UHS lo0
fe80::%lo0/64 link#2 U lo0
fe80::1%lo0 link#2 UHS lo0
ff02::/16 localhost UGRS lo0

1
tests/fixtures/freebsd12/ntpq-p.json vendored Normal file
View File

@@ -0,0 +1 @@
[{"remote": "0.freebsd.pool.", "refid": ".POOL.", "st": 16, "t": "p", "when": null, "poll": 64, "reach": 0, "delay": 0.0, "offset": 0.0, "jitter": 0.0, "state": null}, {"remote": "vf1.bbnx.net", "refid": "252.74.143.178", "st": 2, "t": "u", "when": 1, "poll": 64, "reach": 1, "delay": 387.363, "offset": 1589483.0, "jitter": 39.556, "state": null}, {"remote": "time.airgapped.", "refid": "132.163.96.1", "st": 2, "t": "u", "when": 2, "poll": 64, "reach": 1, "delay": 70.572, "offset": 1589483.0, "jitter": 0.724, "state": null}, {"remote": "clock.trit.net", "refid": "43.77.130.254", "st": 2, "t": "u", "when": 2, "poll": 64, "reach": 1, "delay": 55.717, "offset": 1589483.0, "jitter": 2.021, "state": null}, {"remote": "time.nullrouten", "refid": "132.163.97.1", "st": 2, "t": "u", "when": 1, "poll": 64, "reach": 1, "delay": 59.682, "offset": 1589483.0, "jitter": 7.573, "state": null}]

7
tests/fixtures/freebsd12/ntpq-p.out vendored Normal file
View File

@@ -0,0 +1,7 @@
remote refid st t when poll reach delay offset jitter
==============================================================================
0.freebsd.pool. .POOL. 16 p - 64 0 0.000 0.000 0.000
vf1.bbnx.net 252.74.143.178 2 u 1 64 1 387.363 1589483 39.556
time.airgapped. 132.163.96.1 2 u 2 64 1 70.572 1589483 0.724
clock.trit.net 43.77.130.254 2 u 2 64 1 55.717 1589483 2.021
time.nullrouten 132.163.97.1 2 u 1 64 1 59.682 1589483 7.573

1
tests/fixtures/freebsd12/stat.json vendored Normal file

File diff suppressed because one or more lines are too long

Some files were not shown because too many files have changed in this diff Show More