Skip to content

Instantly share code, notes, and snippets.

@TheTechromancer
TheTechromancer / dhcp_option_121.py
Created November 9, 2019 22:16
DHCP Option 121 (Routes) with Python 3 for pfSense, etc.
#!/usr/bin/env python3
from ipaddress import *
routes = [
# destination # router
('10.0.0.0/24', '172.16.0.2'),
('0.0.0.0/0', '172.16.0.1')
]
@TheTechromancer
TheTechromancer / session_logging.sh
Created February 4, 2021 20:18
Enable complete session logging (input and output) for both normal shells and individual tmux panes
# default tmux config
cat <<EOF > "$HOME/.tmux.conf"
set -g mouse on
set -g history-limit 50000
# List of plugins
set -g @plugin 'tmux-plugins/tmux-logging'
# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'
@TheTechromancer
TheTechromancer / kill_detached_mosh_sessions.sh
Created May 12, 2021 16:22
Kill all detached mosh sessions
kill $(last -f /var/run/utmp | egrep -o 'mosh \[[0-9]+\]' | egrep -o '[0-9]+')
This file has been truncated, but you can view the full file.
# top subdomain append/prepends
# derived from top 1 million subdomains: https://github.com/bitquark/dnspop
401055 {}
8350 {}2
8035 {}1
4012 {}3
2766 {}4
2585 {}01
2183 {}5
@TheTechromancer
TheTechromancer / clean_dns_records.py
Created October 11, 2022 20:39
A simple python script to filter out unresolved/wildcard DNS records.
#!/usr/bin/env python3
import sys
import string
import random
import dns.resolver
import threading
import tldextract
import concurrent.futures
#!/usr/bin/env python3
import sys
import asyncio
from bbot.scanner import Scanner
try:
file = sys.argv[-1]
except KeyError:
@TheTechromancer
TheTechromancer / python_attach_howto.md
Last active February 11, 2025 16:03
Attach to a running python process and explore its state - useful for troubleshooting deadlocks, memory leaks, etc.

Attach to PID with GDB

Prerequisites

  • If running inside docker, make sure to execute docker exec with --privileged
  • Install remote_pdb
pip install remote_pdb
@TheTechromancer
TheTechromancer / prevent_vpn_lockout_ssh.sh
Last active August 23, 2024 04:52
Prevent VPN from locking out SSH
echo <<EOF > /etc/systemd/system/vpn-bypass.service
[Unit]
Description=VPN Bypass for SSH and UDP ports 60000-61000
After=network.target
[Service]
Type=oneshot
# ExecStart=/bin/sh -c 'grep -q "200 vpnbypass" /etc/iproute2/rt_tables || echo "200 vpnbypass" >> /etc/iproute2/rt_tables'
# ExecStart=/bin/sh -c 'ip rule del fwmark 0xca6c lookup 200 priority 100 2>/dev/null || true'
# ExecStart=/bin/sh -c 'ip route add unreachable default metric 4278198272 table 200 2>/dev/null || true'
@TheTechromancer
TheTechromancer / AGENTS.md
Last active July 9, 2026 16:27
A battle-tested AGENTS.md for higher quality code output. Helps avoid "AI slop creep" by keeping your codebase lean and clean.

Agent Guidelines

This document exists to keep the codebase minimal, elegant, and proper.

Modularity Principle

Default to modular. When you design anything with more than one variant — or that will plausibly grow one — the first question is "what's the unit, and how does the rest of the code stay ignorant of which one it's looking at?" That mindset applies at every scale: from a small enum where one method per variant