Skip to content

Instantly share code, notes, and snippets.

@oskar456
oskar456 / bh1750.py
Created June 20, 2015 15:26
BH1750 python library
#!/usr/bin/python2
# vim: expandtab ts=4 sw=4
# Inspired by http://www.raspberrypi-spy.co.uk/2015/03/bh1750fvi-i2c-digital-light-intensity-sensor/
import smbus
import time
class BH1750():
""" Implement BH1750 communication. """
@oskar456
oskar456 / grabsshfp.sh
Last active April 15, 2022 19:48
Generate remotely SSHFP records
#!/bin/bash
set -e
if [[ "$#" -lt 1 ]]; then
echo "Usage: $0 <hostname or IP address>"
exit
fi
host="$1"
@oskar456
oskar456 / authenticatordb2qr.sh
Created May 15, 2016 16:55
Recover installation QR codes from Google Authenticator App DB
#!/bin/sh
echo "select original_name, secret, issuer from accounts;" |\
sqlite3 authenticator.sqlite |\
sed -rn 's_^([^|]+)\|([^|]+)\|(.+)$_otpauth://totp/\1?secret=\2\&issuer=\3_p' |\
while read line
do
ttyqr $line
echo $line
echo ""
@oskar456
oskar456 / isholiday.py
Created June 29, 2016 12:27
Czech public holiday checker
#!/usr/bin/env python3
import datetime
def getholidays(year):
"""Return a set public holidays in CZ as (day, month) tuples."""
holidays = {
(1, 1), #Novy rok
(1, 5), #Svatek prace
(8, 5), #Den vitezstvi
@oskar456
oskar456 / md4pass.sh
Created October 7, 2016 09:48
MSCHAPv2 hash generator one-liner
python -c 'import getpass,hashlib; print(hashlib.new("md4",getpass.getpass().encode("utf-16le")).hexdigest())'
@oskar456
oskar456 / uceprotectpoison.py
Last active May 30, 2018 08:37
Analyse the uceprotect.net DNS poisoning using RIPE atlas
#!/usr/bin/env python3
import requests
from ripe.atlas.sagan import DnsResult
meas_id = 6917800
source = "https://atlas.ripe.net/api/v1/measurement-latest/{}/".format(meas_id)
response = requests.get(source).json()
out = []
@oskar456
oskar456 / blinkclock-init.sh
Created November 22, 2016 09:53
LED blink clock – flash LED every second
#!/bin/sh /etc/rc.common
# Copyright (C) 2016 OpenWrt.org
START=99
USE_PROCD=1
start_service()
{
procd_open_instance
procd_set_param command "/root/blinkclock.py"
@oskar456
oskar456 / rpz_unbound.sh
Last active May 6, 2020 16:49
RPZ policy for unbound - transform RPZ zone into local zone statements
#!/bin/bash
RPZ_ZONE="rpz.cesnet.cz"
RPZ_SERVER="nsa.cesnet.cz"
OUTPUT_FILE="unbound_$RPZ_ZONE.conf"
function resolve_target() {
local domain="$1"
shift
@oskar456
oskar456 / dns_compact.py
Created September 28, 2017 10:35
RIPE Atlas tools custom DNS renderer with compact output (1 result per line)
# Copyright (c) 2017 Ondrej Caletka <ondrej@caletka.cz>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@oskar456
oskar456 / mathpractice.py
Last active May 30, 2018 08:39
Generate a sheet of random math add/subtraction problems for a pre-school child
#!/usr/bin/env python3
import random
import operator
def generate_problem(min_op=1, max_op=9, min_res=0, max_res=10):
operators = [operator.add, operator.sub]
while True:
opa = random.choice(range(min_op, max_op+1))
opb = random.choice(range(min_op, max_op+1))
oper = random.choice(operators)