Last active
October 30, 2017 20:44
-
-
Save mpurzynski/468c8cf6c98e9da427286658b61556fd to your computer and use it in GitHub Desktop.
nooneneedsjq.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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