Skip to content

Instantly share code, notes, and snippets.

@mpurzynski
Last active October 30, 2017 20:44
Show Gist options
  • Select an option

  • Save mpurzynski/468c8cf6c98e9da427286658b61556fd to your computer and use it in GitHub Desktop.

Select an option

Save mpurzynski/468c8cf6c98e9da427286658b61556fd to your computer and use it in GitHub Desktop.
nooneneedsjq.py
import json
import pprint
import sys
def main():
if len(sys.argv) < 4:
print("Must pass <filename>.json src IP dst IP <connection state> arguments")
sys.exit(1)
with open(sys.argv[1], 'r') as f:
pp = pprint.PrettyPrinter(indent=4)
for line in f:
try:
conn = json.loads(line)
except ValueError as e:
print("{0} {1}".format("Cannot read JSON logs", e))
if conn['conn_state'] == sys.argv[4]:
if conn['id.orig_h'] == sys.argv[2]:
if conn['id.resp_h'] == sys.argv[3]:
pp.pprint(conn)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment