mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-19 00:17:51 +02:00
97 lines
1.6 KiB
Markdown
97 lines
1.6 KiB
Markdown
![]() |
# jc.parsers.hosts
|
||
|
jc - JSON CLI output utility hosts Parser
|
||
|
|
||
|
Usage:
|
||
|
specify --hosts as the first argument if the piped input is coming from hosts
|
||
|
|
||
|
Examples:
|
||
|
|
||
|
$ cat /etc/hosts | jc --hosts -p
|
||
|
[
|
||
|
{
|
||
|
"ip": "127.0.0.1",
|
||
|
"hostname": [
|
||
|
"localhost"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"ip": "127.0.1.1",
|
||
|
"hostname": [
|
||
|
"root-ubuntu"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"ip": "::1",
|
||
|
"hostname": [
|
||
|
"ip6-localhost",
|
||
|
"ip6-loopback"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"ip": "fe00::0",
|
||
|
"hostname": [
|
||
|
"ip6-localnet"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"ip": "ff00::0",
|
||
|
"hostname": [
|
||
|
"ip6-mcastprefix"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"ip": "ff02::1",
|
||
|
"hostname": [
|
||
|
"ip6-allnodes"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"ip": "ff02::2",
|
||
|
"hostname": [
|
||
|
"ip6-allrouters"
|
||
|
]
|
||
|
}
|
||
|
]
|
||
|
|
||
|
## process
|
||
|
```python
|
||
|
process(proc_data)
|
||
|
```
|
||
|
|
||
|
Final processing to conform to the schema.
|
||
|
|
||
|
Parameters:
|
||
|
|
||
|
proc_data: (dictionary) raw structured data to process
|
||
|
|
||
|
Returns:
|
||
|
|
||
|
dictionary structured data with the following schema:
|
||
|
|
||
|
[
|
||
|
{
|
||
|
"ip": string,
|
||
|
"hostname": [
|
||
|
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:
|
||
|
|
||
|
dictionary raw or processed structured data
|
||
|
|