Skip to content

Instantly share code, notes, and snippets.

@kellyjonbrazil
kellyjonbrazil / tracebackplus.py
Last active May 7, 2024 18:25
Python Tracebackplus
"""More comprehensive traceback formatting for Python scripts.
To enable this module, do:
import tracebackplus; tracebackplus.enable()
at the top of your script. The optional arguments to enable() are:
logdir - if set, tracebacks are written to files in this directory
context - number of lines of source code to show for each stack frame
@kellyjonbrazil
kellyjonbrazil / fortigate.py
Last active March 21, 2023 12:48
Fortigate configuration parser for JC. Using the fortigate-config-parser library at https://github.com/deyixtan/fortigate-config-parser.
"""jc - JSON Convert Fortigate Configuration file parser
Usage (cli):
$ cat config | jc --fortigate
Usage (module):
import jc
result = jc.parse('fortigate', fortigate_config_file_string)
@kellyjonbrazil
kellyjonbrazil / scansubnet.sh
Last active November 4, 2022 01:20
Subnet Scan Bash Script
#!/bin/bash
# Requires: ifconfig, ping, arp, date, wc, jq, and jc
if [[ $1 == "" ]]; then
echo "Please enter the interface name as command argument."
echo
echo "Options:"
# Only show interfaces with an assigned IP address
jc ifconfig | jq -r '.[] | select(.ipv4_addr != null) | .name'
@kellyjonbrazil
kellyjonbrazil / dpkg_l_ru.py
Last active July 26, 2022 17:10
jc dpkg-l parser for Russian locale
"""jc - JSON Convert `dpkg -l` command output parser for Russia locale
Set the `COLUMNS` environment variable to a large value to avoid field
truncation. For example:
$ COLUMNS=500 dpkg -l | jc --dpkg-l
Usage (cli):
$ dpkg -l | jc --dpkg-l
@kellyjonbrazil
kellyjonbrazil / tr2dot.py
Created August 3, 2021 22:23
Generate graphviz dot graph from traceroute command output
#!/usr/bin/env python3
#
# Convert traceroute command output to a graphviz DOT graph
# Use `jc` to convert `traceroute` output to JSON before piping to tr2dot.py
#
# Version 1.0
# Kelly Brazil (kellyjonbrazil@gmail.com)
#
# Requires graphviz (pip3 install graphviz)
#
@kellyjonbrazil
kellyjonbrazil / jc.py
Created September 15, 2020 15:57
Saltstack JC Serializer
"""
salt.serializers.jc
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Implements JC serializer.
JC converts the output of many commands and file-types to structured format.
https://github.com/kellyjonbrazil/jc
Requires JC is installed via pip: $ pip3 install jc
Requires Python >= 3.6
@kellyjonbrazil
kellyjonbrazil / jc.py
Last active September 15, 2020 15:56
Saltstack JC Outputter
# -*- coding: utf-8 -*-
"""
JC Outputter for Salt
JC converts the output of many commands and file-types to structured format.
https://github.com/kellyjonbrazil/jc
Requires JC is installed via pip: $ pip3 install jc
Requires Python >= 3.6
Usage:
This outputter requires a parser to be defined via the JC_PARSER env variable: