Skip to content

Instantly share code, notes, and snippets.

Avatar

Mike Riebart

View GitHub Profile
@Riebart
Riebart / pb_notify.sh
Created Apr 13, 2017
A bash function that sends a pushbullet notification when a command completes
View pb_notify.sh
function pb_notify {
start=`date +%s%N`
"$@"
end=`date +%s%N`
start_ms=`echo $start | head -c 13`
end_ms=`echo $end | head -c 13`
dt_ms=$[(end_ms-start_ms)]
if which bc >/dev/null 2>&1
then
dt=`echo "scale=3;$dt_ms/1000.0" | bc`
@Riebart
Riebart / ip4list_to_ranges.py
Last active Sep 15, 2017
Collect a list of IPv4 addresses into contiguous range blocks.
View ip4list_to_ranges.py
#!/usr/bin/env python
"""
Given a list of IP addresses (or IP address ranges), one per line (with ranges given as "IP1-IP2"),
return a list of IP address ranges that represent the smallest possible list of IP address ranges
that does not contain any addresses not represented in the input list.
Only supports IPv4.
"""
import sys
View keybase.md

Keybase proof

I hereby claim:

  • I am Riebart on github.
  • I am riebart (https://keybase.io/riebart) on keybase.
  • I have a public key whose fingerprint is 277C D4E5 2742 A486 CAB0 C857 98B6 9479 9B76 0FBE

To claim this, I am signing this object:

View packet_bucket.py
from random import random
def accumulate(iterator):
total = 0
for item in iterator:
total += item
yield total
# Generate a list of a bunch of values with random offsets so we can bucket them.
# Only step at most 10ms per 'packet', because we want a representative sample size.
@Riebart
Riebart / vscode_context.reg
Created Nov 10, 2017
Registry entries for Explorer context menus. Useful for non-admin installs
View vscode_context.reg
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Classes\*\shell]
[HKEY_CURRENT_USER\Software\Classes\*\shell\VSCode]
@="Open with Code"
"Icon"=hex(2):43,00,3a,00,5c,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,20,\
00,46,00,69,00,6c,00,65,00,73,00,5c,00,4d,00,69,00,63,00,72,00,6f,00,73,00,\
6f,00,66,00,74,00,20,00,56,00,53,00,20,00,43,00,6f,00,64,00,65,00,5c,00,43,\
00,6f,00,64,00,65,00,2e,00,65,00,78,00,65,00,00,00
@Riebart
Riebart / scapy_dns_response.py
Created Apr 26, 2018
Read in a file, and respond to any query received with the contents of that file in the CNAME target.
View scapy_dns_response.py
from __future__ import print_function
from scapy.all import *
domain_name = "nhlscore.riebart.ca"
dns_server_ip = '172.31.15.145'
bpf_filter = 'dst port 53 and ip dst {0}'.format(dns_server_ip)
def dns_respond(pkt, rcode=0):
if (DNS in pkt and pkt[DNS].opcode == 0 and pkt[DNS].ancount == 0):
print('Responding to query for "%s" from "%s"' % (pkt[DNSQR].qname, pkt[IP].src))
@Riebart
Riebart / grafana_timeseries.sh
Last active Jun 27, 2018
Ad hoc stuffing timeseries into InfluxDB for visualization with Grafana with subsecond resolution timestamps.
View grafana_timeseries.sh
#!/bin/bash
influxId=$(docker run --rm -d -p 8086:8086 -p 2003:2003 -e INFLUXDB_GRAPHITE_ENABLED=true influxdb)
grafanaId=$(docker run --rm -d -p 3000:3000 grafana/grafana)
echo "Sleeping while the containers spool up..." >&2
sleep 10
influxIp=$(docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ${influxId})
@Riebart
Riebart / wss-iam-listener.py
Last active Oct 31, 2018
Python script to listen to an AWS IoT Messaging endpoint, authenticating with IAM, and printing messages as they arrive.
View wss-iam-listener.py
#!/usr/bin/env python3
"""
Provide a simple wrapper for listening to an MQTT stream from an AWS IoT websocket endpoint. Prints messages to stdout.
"""
try:
from urllib.parse import urlparse, urlencode, parse_qs
except ImportError:
from urlparse import urlparse, parse_qs
from urllib import urlencode
@Riebart
Riebart / userdata.sh
Created Jan 10, 2018
EC2 user data for setting up an EC2 instance with SSM and deploying into an ECS cluster.
View userdata.sh
#!/bin/bash
# Install the SSM agent:
# Ref: https://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-install-startup-linux.html
cd /tmp
sudo yum install -y https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm
sudo start amazon-ssm-agent
echo ECS_CLUSTER="ECS_CLUSTER_NAME" >> /etc/ecs/ecs.config
export PATH=/usr/local/bin:$PATH
@Riebart
Riebart / pihole_docker.sh
Created Jul 15, 2019
Start a PiHole docker container with the appropriate upstream DNS and server IPs autodetected.
View pihole_docker.sh
#!/bin/bash
docker run --rm -d --name pihole \
-p 53:53/tcp -p 53:53/udp -p 80:80 \
-v /home/pihole/etc/pihole:/etc/pihole/ \
-v /home/pihole/etc/dnsmasq.d:/etc/dnsmasq.d/ \
--dns $(nslookup 1.1.1.1 | \
grep Server: | tr -s '\t' | \
cut -f2) \
-e DNS1=$(nslookup 1.1.1.1 | \