mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-19 00:17:51 +02:00
23 lines
555 B
Python
23 lines
555 B
Python
"""jc - JSON CLI output utility arp Parser
|
|
|
|
Usage:
|
|
specify --arp as the first argument if the piped input is coming from arp
|
|
|
|
Example:
|
|
|
|
$ arp | jc --arp -p
|
|
|
|
"""
|
|
|
|
|
|
def parse(data):
|
|
|
|
# code adapted from Conor Heine at:
|
|
# https://gist.github.com/cahna/43a1a3ff4d075bcd71f9d7120037a501
|
|
|
|
cleandata = data.splitlines()
|
|
headers = [h for h in ' '.join(cleandata[0].lower().strip().split()).split() if h]
|
|
|
|
raw_data = map(lambda s: s.strip().split(None, len(headers) - 1), cleandata[1:])
|
|
return [dict(zip(headers, r)) for r in raw_data]
|