Skip to content

Instantly share code, notes, and snippets.

View pocc's full-sized avatar
🏠
Working from home

Ross Jacobs pocc

🏠
Working from home
View GitHub Profile
@pocc
pocc / png_to_webp.sh
Last active November 9, 2023 14:03
Convert all png images to webp recursively
#!/usr/bin/env bash
# This script will get a list of all jpg and png files recursively
# and convert them all in place to webp files.
# cwebp options for max compression: `-m 6 -q 100 -z 9`
shopt -s globstar
for image in $PWD/**/*.png; do
echo "File is $image"
outfile=${image::-4}.webp
echo "outfile is $outfile"
@pocc
pocc / wsutils.py
Created March 18, 2019 15:35
Wrapper for wireshark utils (like pyshark for tshark)
"""
Pcap class to more easily interact with pcaps
When in doubt, aim for simplicity of requests API
Like pyshark, but for the wireshark utilities
"""
import os
import subprocess as sp
import re
import pprint
import tempfile
@pocc
pocc / dl_livecap.sh
Last active March 2, 2021 16:35
Live capture a Chrome or Firefox pcap/ng download as it is downloading
#!/usr/bin/env bash
# This script will detect if there are any new partial download files
# And launch wire/tshark to read them as a live capture.
DL_DIR="$HOME/Downloads"
SHARK_CMD="wireshark -k -i -"
# SHARK_CMD="tshark -r -"
function DL_PARTIALS {
# Partial names: Chrome=$file.crdownload, Firefox=$file.part, Safari=$file.download, Edge=$file.RaNd0mStr.partial
find "$DL_DIR" -maxdepth 1 | perl -ne 'print /(.*pcapng\.(part|crdownload|download|[a-zA-Z0-9]+\.partial))/'
@pocc
pocc / scapy_example.py
Created March 28, 2019 01:34
Send udp/tcp/icmp pings in Scapy to top 50 websites and watch those packets appear in a Wireshark live capture
#!/usr/bin/env python3
# Run `tail -f -n +1 /tmp/scapy.pcap | wireshark -k -i -` in another terminal
import re
import requests
from scapy.all import *
LIVE_PCAP="/tmp/scapy.pcap"
def top_50_websites():
@pocc
pocc / wsl_tshark.sh
Last active March 23, 2021 02:50
Use WSL tshark to colorize output and Windows tshark for everything else
#!/usr/bin/env bash
# Copyright 2019 Ross Jacobs
#
# tshark --color on Windows is limited to 16 colors vs 24-bit "true color"
# on other platforms. This script uses both WSL and Windows tshark in
# order to get color parity on Windows.
#
# Install:
# Add this function to your WSL ~/.bashrc and then `source ~/.bashrc`
#
@pocc
pocc / octave.py
Last active April 7, 2019 21:25
Play a full octave using pysine
# Play all notes between 440-880hz, inclusive
from pysine import sine
def get_freq(key):
# For a given piano key, return the frequency
# Taken from https://en.wikipedia.org/wiki/Piano_key_frequencies
return 2**((key-49)/12) * 440
for key in range(49, 62):
freq = get_freq(key)
@pocc
pocc / build_wireshark.sh
Created April 8, 2019 16:38
Build Wireshark 3.0.0 on Ubuntu 18.04
cd /tmp
wget https://www.wireshark.org/download/src/wireshark-3.0.0.tar.xz
tar -xzf wireshark-3.0.0.tar.xz
cd wireshark-3.0.0
sudo apt update && sudo apt dist-upgrade
sudo apt install cmake libglib2.0-dev libgcrypt20-dev flex bison byacc libpcap-dev qtbase5-dev libssh-dev libsystemd-dev qtmultimedia5-dev libqt5svg5-dev qttools5-dev
cmake .
make
@pocc
pocc / reshark.py
Last active April 10, 2019 18:27
Filters packets by a regex applied to a display filter
#!/usr/bin/env python3
# Desc:
# Create a pcap where the output of a display filter matches
# a given regex. Generates a file named re_<pcap in name>
# tshark MUST be on the path for this to work
#
# Usage:
# Using the `arp-storm.pcap` from https://wiki.wireshark.org/SampleCaptures
# To match all packets whose seconds part of the timestamp ends in 3:
#
@pocc
pocc / .pre-commit-config.yaml
Created April 19, 2019 15:15
Initial pre-commit (likely has errors)
# Ross Jacobs pre-commit file
exclude: ''
fail_fast: false
minimum_pre_commit_version: 0
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.1.0 # Use the ref you want to point at
hooks:
# Checks
- id: check-added-large-files
@pocc
pocc / channel_test.go
Last active May 26, 2019 21:13
Find channel IO overhead
/* Benchmarks summing serially and then with channels
* to time how much overhead channel reads have.
* To run: `go test -bench . channel_test.go`
*/
package channel_test
import (
"sync"
"testing"
)