Skip to content

Instantly share code, notes, and snippets.

@oskar456
oskar456 / ctlogids.py
Last active March 28, 2018 20:34
Show Certificate Transparency Log IDs compatible with OpenSSL output
#!/usr/bin/env python3
import requests
import hashlib
import base64
log_list = "https://www.gstatic.com/ct/log_list/all_logs_list.json"
logs = requests.get(log_list).json()
for log in logs['logs']:
@oskar456
oskar456 / fixmime.py
Created January 4, 2018 14:48
Milter to fix badly formatted MIME messages
#!/usr/bin/env python3
import email
from email.mime.multipart import MIMEMultipart
import sys
from subprocess import Popen, PIPE
def reformat(msg):
"""Reformat the MIME parts of the message to a sane one."""
newmsg = MIMEMultipart()
@oskar456
oskar456 / py6server.py
Created December 5, 2017 12:59
Simple Python-based HTTP Server with IPv6 support
#!/usr/bin/env python3
import http.server
import socketserver
import socket
class TCP6Server(socketserver.TCPServer):
address_family = socket.AF_INET6
def server_bind(self):
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
@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)
@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 / 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 / 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 / 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 / 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 / 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