Skip to content

Instantly share code, notes, and snippets.

@porjo
porjo / random_ip.go
Created February 11, 2019 00:12
Generate random IPs with Go
package main
import (
"encoding/binary"
"fmt"
"math/rand"
"net"
)
func main() {

My TrueNAS Scale server recently started throwing the following zfs module kernel panic on boot:

PANIC at space_map.c:405:space_map_load_callback()

What follows are the steps I took to retrieve the data from the corrupted zfs pool.

Getting setup

@porjo
porjo / rsyslog_selinux_centos6.md
Last active May 3, 2025 03:52
Rsyslog and selinux on Centos6

Rsyslog and selinux on Centos6

I was configuring a Centos6 box to receive syslog from remote hosts. I wanted that log to be written to a non-standard path: /data/syslog

On my first attempt, this failed with the following log in /var/log/messages:

Nov 26 11:26:24 localhost rsyslogd-3000: Could not open dynamic file '/data/syslog/10.10.1.252/2014-11/26/syslog.log' [state -3000] - discarding message [try http://www.rsyslog.com/e/3000 ]

I then set the context of /data/syslog to match /var/log with:

@porjo
porjo / docker_ipv6.md
Last active May 3, 2025 03:50
Docker IPv6

Docker IPv6

The scenario is where the ISP assigns a /104 IPv6 network 'on link' (i.e. not routed): xxxx:yyyy:1::9c3:0:0/104

Configure Linux host

Add the following to /etc/sysctl.conf:

# Accept Router Advertisements even if forwarding is enabled.
net.ipv6.conf.eth0.accept_ra = 2
@porjo
porjo / jq_cheatsheet.md
Last active May 3, 2025 03:50
jq JSON utility - cheatsheet

Apache Logs

Output entries between 2 times, showing IP and query

$ cat access_log.json | \
  jq -r 'select (.time > "2017-10-21T02:00:00.000Z" and .time < "2017-10-22T02:00:00.000Z") | [.remote_addr,.query] | @csv'

Output entries where client IP matches prefix

$ cat access_log.json | \
@porjo
porjo / ssl_CN_lookup_by_IP.sh
Created December 6, 2019 00:29
Given a list of IP addresses (in file 'ips') find what the SSL CN (subject) is for each one.
#!/bin/bash
# Given a list of IP addresses (in file 'ips') find what the SSL CN (subject) is for each one.
echo -en "IP\tSSL CN\n"
for i in `cat ips`; do
echo -en "$i\t"
out=`timeout 2 bash -c "openssl s_client -showcerts -connect $i:443 < /dev/null 2> /dev/null | openssl x509 -noout -subject 2> /dev/null | grep 'subject=' | sed -rn 's/.*CN=([^ /]+).*/\1/p'"`
if [ $? -eq 124 ]; then
echo "(timeout)"
@porjo
porjo / dump_route53_records.md
Last active February 12, 2025 02:08
Export route53 records to CSV

Retrieve hosted zones with aws route53 list-hosted-zones then enter the zone Id below:

aws route53 list-resource-record-sets --hosted-zone-id "/hostedzone/xxxxxxxxxxx" | \
   jq -r '.ResourceRecordSets[] | [.Name, .Type, (.ResourceRecords[]? | .Value), .AliasTarget.DNSName?]  | @tsv'
@porjo
porjo / pulseaudio_rtp.md
Last active March 28, 2024 21:01
Use Pulseaudio to stream audio file to network via RTP

RTP Server

Setup

pacmd load-module module-null-sink sink_name=rtp format=s16le channels=1 rate=16000
pacmd load-module module-rtp-send source=rtp.monitor

This sets up a multicast socket for RTP streams. When I tested this was 224.0.0.56:46136

@porjo
porjo / ipset_update.sh
Last active June 8, 2023 12:49
Create Geo fencing country blocks for use by iptables
#!/bin/bash
#
# Update the ipset that iptables references for allowing/blocking based on country.
# Takes 2 parameters: ipset name (no spaces), country name e.g. 'Australia'
#
# iptables should have an existing '--match-set' rule e.g
# $ iptables -I INPUT -p tcp --dport 22 -m set --match-set australia4 src -j ACCEPT
# $ ip6tables -I INPUT -p tcp --dport 22 -m set --match-set australia6 src -j ACCEPT
#
@porjo
porjo / timelapse.md
Last active May 25, 2023 16:14
ffmpeg time-lapse

Convert sequence of JPEG images to MP4 video

Simple glob:

ffmpeg -r 24 -i '*.JPG' -s hd1080 -vcodec libx264 timelapse.mp4

Start from DSC_0079.JPG

ffmpeg -r 24 -f image2 -start_number 79 -i DSC_%04d.JPG -s hd1080 -vcodec libx264 timelapse2.mp4