mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-07-17 01:32:37 +02:00
fixes and docs for airport parser issue #46
This commit is contained in:
22
README.md
22
README.md
@ -82,6 +82,7 @@ jc [OPTIONS] COMMAND
|
|||||||
The JSON output can be compact (default) or pretty formatted with the `-p` option.
|
The JSON output can be compact (default) or pretty formatted with the `-p` option.
|
||||||
|
|
||||||
### Parsers
|
### Parsers
|
||||||
|
- `--airport` enables the `airport` command parser (OSX)
|
||||||
- `--arp` enables the `arp` command parser
|
- `--arp` enables the `arp` command parser
|
||||||
- `--blkid` enables the `blkid` command parser
|
- `--blkid` enables the `blkid` command parser
|
||||||
- `--crontab` enables the `crontab` command and file parser
|
- `--crontab` enables the `crontab` command and file parser
|
||||||
@ -164,6 +165,27 @@ Tested on:
|
|||||||
- Excellent constructive feedback from Ilya Sher (https://github.com/ilyash-b)
|
- Excellent constructive feedback from Ilya Sher (https://github.com/ilyash-b)
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
### airport
|
||||||
|
```
|
||||||
|
$ airport | jc --airport -p
|
||||||
|
{
|
||||||
|
"agrctlrssi": -66,
|
||||||
|
"agrextrssi": 0,
|
||||||
|
"agrctlnoise": -90,
|
||||||
|
"agrextnoise": 0,
|
||||||
|
"state": "running",
|
||||||
|
"op_mode": "station",
|
||||||
|
"lasttxrate": 195,
|
||||||
|
"maxrate": 867,
|
||||||
|
"lastassocstatus": 0,
|
||||||
|
"802_11_auth": "open",
|
||||||
|
"link_auth": "wpa2-psk",
|
||||||
|
"bssid": "3c:37:86:15:ad:f9",
|
||||||
|
"ssid": "SnazzleDazzle",
|
||||||
|
"mcs": 0,
|
||||||
|
"channel": "48,80"
|
||||||
|
}
|
||||||
|
```
|
||||||
### arp
|
### arp
|
||||||
```
|
```
|
||||||
$ arp | jc --arp -p # or: jc -p arp
|
$ arp | jc --arp -p # or: jc -p arp
|
||||||
|
@ -13,12 +13,40 @@ Examples:
|
|||||||
|
|
||||||
$ airport | jc --airport -p
|
$ airport | jc --airport -p
|
||||||
{
|
{
|
||||||
|
"agrctlrssi": -66,
|
||||||
|
"agrextrssi": 0,
|
||||||
|
"agrctlnoise": -90,
|
||||||
|
"agrextnoise": 0,
|
||||||
|
"state": "running",
|
||||||
|
"op_mode": "station",
|
||||||
|
"lasttxrate": 195,
|
||||||
|
"maxrate": 867,
|
||||||
|
"lastassocstatus": 0,
|
||||||
|
"802_11_auth": "open",
|
||||||
|
"link_auth": "wpa2-psk",
|
||||||
|
"bssid": "3c:37:86:15:ad:f9",
|
||||||
|
"ssid": "SnazzleDazzle",
|
||||||
|
"mcs": 0,
|
||||||
|
"channel": "48,80"
|
||||||
}
|
}
|
||||||
|
|
||||||
$ airport | jc --airport -p -r
|
$ airport | jc --airport -p -r
|
||||||
{
|
{
|
||||||
|
"agrctlrssi": "-66",
|
||||||
|
"agrextrssi": "0",
|
||||||
|
"agrctlnoise": "-90",
|
||||||
|
"agrextnoise": "0",
|
||||||
|
"state": "running",
|
||||||
|
"op_mode": "station",
|
||||||
|
"lasttxrate": "195",
|
||||||
|
"maxrate": "867",
|
||||||
|
"lastassocstatus": "0",
|
||||||
|
"802_11_auth": "open",
|
||||||
|
"link_auth": "wpa2-psk",
|
||||||
|
"bssid": "3c:37:86:15:ad:f9",
|
||||||
|
"ssid": "SnazzleDazzle",
|
||||||
|
"mcs": "0",
|
||||||
|
"channel": "48,80"
|
||||||
}
|
}
|
||||||
|
|
||||||
## info
|
## info
|
||||||
@ -42,7 +70,21 @@ Returns:
|
|||||||
Dictionary. Structured data with the following schema:
|
Dictionary. Structured data with the following schema:
|
||||||
|
|
||||||
{
|
{
|
||||||
|
"agrctlrssi": integer,
|
||||||
|
"agrextrssi": integer,
|
||||||
|
"agrctlnoise": integer,
|
||||||
|
"agrextnoise": integer,
|
||||||
|
"state": string,
|
||||||
|
"op_mode": string,
|
||||||
|
"lasttxrate": integer,
|
||||||
|
"maxrate": integer,
|
||||||
|
"lastassocstatus": integer,
|
||||||
|
"802_11_auth": string,
|
||||||
|
"link_auth": string,
|
||||||
|
"bssid": string,
|
||||||
|
"ssid": string,
|
||||||
|
"mcs": integer,
|
||||||
|
"channel": string
|
||||||
}
|
}
|
||||||
|
|
||||||
## parse
|
## parse
|
||||||
|
@ -12,12 +12,40 @@ Examples:
|
|||||||
|
|
||||||
$ airport | jc --airport -p
|
$ airport | jc --airport -p
|
||||||
{
|
{
|
||||||
|
"agrctlrssi": -66,
|
||||||
|
"agrextrssi": 0,
|
||||||
|
"agrctlnoise": -90,
|
||||||
|
"agrextnoise": 0,
|
||||||
|
"state": "running",
|
||||||
|
"op_mode": "station",
|
||||||
|
"lasttxrate": 195,
|
||||||
|
"maxrate": 867,
|
||||||
|
"lastassocstatus": 0,
|
||||||
|
"802_11_auth": "open",
|
||||||
|
"link_auth": "wpa2-psk",
|
||||||
|
"bssid": "3c:37:86:15:ad:f9",
|
||||||
|
"ssid": "SnazzleDazzle",
|
||||||
|
"mcs": 0,
|
||||||
|
"channel": "48,80"
|
||||||
}
|
}
|
||||||
|
|
||||||
$ airport | jc --airport -p -r
|
$ airport | jc --airport -p -r
|
||||||
{
|
{
|
||||||
|
"agrctlrssi": "-66",
|
||||||
|
"agrextrssi": "0",
|
||||||
|
"agrctlnoise": "-90",
|
||||||
|
"agrextnoise": "0",
|
||||||
|
"state": "running",
|
||||||
|
"op_mode": "station",
|
||||||
|
"lasttxrate": "195",
|
||||||
|
"maxrate": "867",
|
||||||
|
"lastassocstatus": "0",
|
||||||
|
"802_11_auth": "open",
|
||||||
|
"link_auth": "wpa2-psk",
|
||||||
|
"bssid": "3c:37:86:15:ad:f9",
|
||||||
|
"ssid": "SnazzleDazzle",
|
||||||
|
"mcs": "0",
|
||||||
|
"channel": "48,80"
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
import jc.utils
|
import jc.utils
|
||||||
@ -51,20 +79,32 @@ def process(proc_data):
|
|||||||
Dictionary. Structured data with the following schema:
|
Dictionary. Structured data with the following schema:
|
||||||
|
|
||||||
{
|
{
|
||||||
|
"agrctlrssi": integer,
|
||||||
|
"agrextrssi": integer,
|
||||||
|
"agrctlnoise": integer,
|
||||||
|
"agrextnoise": integer,
|
||||||
|
"state": string,
|
||||||
|
"op_mode": string,
|
||||||
|
"lasttxrate": integer,
|
||||||
|
"maxrate": integer,
|
||||||
|
"lastassocstatus": integer,
|
||||||
|
"802_11_auth": string,
|
||||||
|
"link_auth": string,
|
||||||
|
"bssid": string,
|
||||||
|
"ssid": string,
|
||||||
|
"mcs": integer,
|
||||||
|
"channel": string
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
# boolean changes
|
# integer changes
|
||||||
'''
|
int_list = ['agrctlrssi', 'agrextrssi', 'agrctlnoise', 'agrextnoise',
|
||||||
bool_list = ['ntp_enabled', 'ntp_synchronized', 'rtc_in_local_tz', 'dst_active',
|
'lasttxrate', 'maxrate', 'lastassocstatus', 'mcs']
|
||||||
'system_clock_synchronized', 'systemd-timesyncd.service_active']
|
|
||||||
for key in proc_data:
|
for key in proc_data:
|
||||||
if key in bool_list:
|
if key in int_list:
|
||||||
try:
|
try:
|
||||||
proc_data[key] = True if proc_data[key] == 'yes' else False
|
proc_data[key] = int(proc_data[key])
|
||||||
except (ValueError):
|
except (ValueError):
|
||||||
proc_data[key] = None
|
proc_data[key] = None
|
||||||
'''
|
|
||||||
|
|
||||||
return proc_data
|
return proc_data
|
||||||
|
|
||||||
@ -90,7 +130,7 @@ def parse(data, raw=False, quiet=False):
|
|||||||
|
|
||||||
for line in filter(None, data.splitlines()):
|
for line in filter(None, data.splitlines()):
|
||||||
linedata = line.split(':', maxsplit=1)
|
linedata = line.split(':', maxsplit=1)
|
||||||
raw_output[linedata[0].strip().lower().replace(' ', '_')] = linedata[1].strip()
|
raw_output[linedata[0].strip().lower().replace(' ', '_').replace('.', '_')] = linedata[1].strip()
|
||||||
|
|
||||||
if raw:
|
if raw:
|
||||||
return raw_output
|
return raw_output
|
||||||
|
1
tests/fixtures/osx-10.14.6/airport-I.json
vendored
Normal file
1
tests/fixtures/osx-10.14.6/airport-I.json
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"agrctlrssi": -66, "agrextrssi": 0, "agrctlnoise": -90, "agrextnoise": 0, "state": "running", "op_mode": "station", "lasttxrate": 195, "maxrate": 867, "lastassocstatus": 0, "802_11_auth": "open", "link_auth": "wpa2-psk", "bssid": "3c:37:86:15:ad:f9", "ssid": "SnazzleDazzle", "mcs": 0, "channel": "48,80"}
|
2
tests/fixtures/osx-10.14.6/airport-I.out
vendored
2
tests/fixtures/osx-10.14.6/airport-I.out
vendored
@ -10,6 +10,6 @@ lastAssocStatus: 0
|
|||||||
802.11 auth: open
|
802.11 auth: open
|
||||||
link auth: wpa2-psk
|
link auth: wpa2-psk
|
||||||
BSSID: 3c:37:86:15:ad:f9
|
BSSID: 3c:37:86:15:ad:f9
|
||||||
SSID: BrazzleDazzle
|
SSID: SnazzleDazzle
|
||||||
MCS: 0
|
MCS: 0
|
||||||
channel: 48,80
|
channel: 48,80
|
||||||
|
Reference in New Issue
Block a user