Skip to content

Instantly share code, notes, and snippets.

View Jcpetrucci's full-sized avatar

John C. Petrucci Jcpetrucci

View GitHub Profile
@Jcpetrucci
Jcpetrucci / .bashrc
Last active October 30, 2015 19:14
Plot ping response times in ASCII graph.
function pingplot {
local destination="$1"
[[ -n $destination ]] || read -rp 'Ping host: ' destination;
results="$(mktemp)";
ping "$destination" | sed -ur 's/^PING.*//;s/.*seq=([0-9]+)/\1/;s/ttl.*time=([0-9]+).*/\1/' > "$results" &
sleep 1 && pidof ping || { echo Something went wrong with the ping.; return 1; }
watch "tail -100 "$results" | gnuplot -e \"set key off; set title 'Pinging: $destination'; set terminal dumb size $((COLUMNS - 5)) 25; plot '/dev/stdin' w lp;\"";
kill %ping
rm "$results"
}
@Jcpetrucci
Jcpetrucci / startup.sh
Last active January 23, 2018 08:22
Unseen DHCP client alert (DD-WRT)
#!/bin/sh
# Generates a syslog message w/ prio=emerg for any DHCP client we haven't seen since last reboot.
# Note: Syslog server is configured to send SMTP on any event >= emerg. This script alone does not send the mail.
echo '#!/bin/sh
op="${1:-op}"
mac="${2:-mac}"
ip="${3:-ip}"
hostname="${4}"
grep "$mac" /tmp/dnsmasq-leases.log || { export priority=emerg; echo "$mac" "$hostname" >> /tmp/dnsmasq-leases.log; }
@Jcpetrucci
Jcpetrucci / panos-object-creator.sh
Last active August 29, 2015 14:13
Creates PAN-OS CLI configuration syntax out of large groups of IP/NETMASK data.
#!/bin/bash
# Creates PAN-OS CLI configuration syntax out of large groups of IP/NETMASK data.
[[ "$#" == 1 && -f "$1" ]] || { printf "First argument should be filename containing networks in form of '#.#.#.#/#'.\n" >&2; exit 1; }
OUTFILE="$(mktemp)"
exec 3<> "$OUTFILE"
read -r -p "Address description value (e.g. CHG number): " DESCRIPTION
while FS='' read -r line; do
grep -Eq "([0-9]+\.){3}[0-9]+/[0-9]+" <<<"$line" || {
printf "Line does not match expected format. Line: %s\n" "$line" >&2;
exit 1;
@Jcpetrucci
Jcpetrucci / bruteforce.ahk
Created February 15, 2015 21:49
Brute force passwords with AutoHotKey
DetectHiddenWindows on
DetectHiddenText on
;SetTitleMatchMode 2
;SetTitleMatchMode Slow
#z::
SetKeyDelay 100
Loop, read, D:\wordlist.txt
{
TrayTip Now trying:, %A_LoopReadLine%, 1 ;Creates tooltip so we can monitor the progress through wordlist.
SendRaw %A_LoopReadLine% ;Type the current line into box
@Jcpetrucci
Jcpetrucci / keybase.md
Created March 3, 2015 16:31
Nothing cool here, just keybase.io verification.

Keybase proof

I hereby claim:

  • I am jcpetrucci on github.
  • I am petrucci (https://keybase.io/petrucci) on keybase.
  • I have a public key whose fingerprint is 1DD7 F96E C6B0 35B0 602C AFF7 9DD9 C5E7 3EDB 622E

To claim this, I am signing this object:

@Jcpetrucci
Jcpetrucci / keybase-hash.sh
Last active August 29, 2015 14:16
Manually produce a keybase.io hash
#!/bin/bash
# Original: https://github.com/keybase/keybase-issues/issues/1126#issuecomment-58430029
gpg --dearmor | \
sha256sum | \
awk ' { print "0:", $1 } ' | \
xxd -g0 -r -c256 | \
base64 | \
head -c 43
@Jcpetrucci
Jcpetrucci / rotX.sh
Last active August 14, 2019 08:54
Tries all variations of Rot# (i.e. Rot13...Rot14...RotN)
#!/bin/bash
charset=abcdefghijklmnopqrstuvwxyz # Tweak $charset as needed for your alphabet
input=${1,,} #strtolower; greatly simplifies conversion
for char in $(seq 1 ${#charset}); do # Count characters in charset, and for each...
temp=${charset#?} # Strip the first character, save rest to $temp
charset=${temp}${charset%"$temp"} # Move the first character of charset behind the rest (abcde becomes bcdea)
echo $input | tr a-z $charset
done
@Jcpetrucci
Jcpetrucci / checkpoint-object-creator.sh
Created April 2, 2015 17:57
Creates dbedit (Check Point) CLI configuration syntax out of large groups of IP address data.
#!/bin/bash
# Creates dbedit CLI configuration syntax out of large groups of IP address data.
[[ "$#" == 1 && -f "$1" ]] || { printf "First argument should be filename containing IP addresses in form of '#.#.#.#'.\n" >&2; exit 1; }
OUTFILE="$(mktemp)"
exec 3<> "$OUTFILE"
# Make group of objects just created
read -r -p "Group name (e.g. 'blacklist'): " GROUPNAME
#read -r -p "Host prefix (e.g. 'badip'): " PREFIX # Don't feel like sanitizing this at the moment. I'll just hardcode a prefix on the next line.
PREFIX="host_"
@Jcpetrucci
Jcpetrucci / fibonacci.sh
Created July 3, 2015 02:55
fibonacci golf in 58 characters (bash)
until((${#c}>8));do
a=$b
b=${c-1}
c=$((b+a))
echo $c
done
@Jcpetrucci
Jcpetrucci / panorama-rollback.sh
Created July 15, 2016 13:02
Run tmux on a server in the same subnet as Palo Alto Panorama. After a delay, tmux emulates your keystrokes to rollback the config.
#!/bin/bash
which tmux >/dev/null || { printf '%s\n' 'Error: could not locate tmux.' >&2; exit 1; }
# Create session, window, pane
readonly SESSION_NAME="$(head -c 30 <(tr -d -c [:alnum:] </dev/urandom))"
tmux start-server
tmux new-session -d -s $SESSION_NAME
tmux split-window -d -v -p 10
# Configure timer: