Skip to content

Instantly share code, notes, and snippets.

View dlenski's full-sized avatar

Dan Lenski dlenski

View GitHub Profile
@dlenski
dlenski / geoclue.py
Created December 18, 2019 01:32
Playing around with freedesktop/python-geoclue
#!/usr/bin/env python
# old, Python 2.x only :-(
# https://github.com/freedesktop/python-geoclue
from __future__ import print_function
import Geoclue
from datetime import datetime
print("Geoclue version %s" % Geoclue.VERSION)
@dlenski
dlenski / formatted_link.js
Created January 30, 2020 03:30
Bookmarklet to copy current page title as a rich-text formatted link
@dlenski
dlenski / cert_fingerprint_test.py
Last active February 26, 2024 09:05
Fingerprint-based certificate validation in Python (including pin-sha256)
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# This is a demonstration of how to do fingerprint-based certificate
# validation in Python, in the style of OpenConnect:
# https://gitlab.com/openconnect/openconnect/-/blob/HEAD/library.c#L1084-1143
#
# For Python <3.7, we monkey-patch ssl.SSLSocket directly, because ssl.SSLContext.sslsocket_class
# isn't available until Python 3.7. For Python 3.7+, we set ssl.SSLContext.sslsocket_class
# to our modified version (which is sort of monkey-patching too).
@dlenski
dlenski / procnet.py
Last active August 28, 2023 13:54
Print /proc/net/{tcp,udp}{,6} in a more human-readable format
#!/usr/bin/python3
import argparse
from ipaddress import IPv4Address, IPv6Address
from binascii import unhexlify
from struct import unpack
import tabulate
def hexint(x):
return int(x, 16)
@dlenski
dlenski / jwt-parse.sh
Last active December 8, 2021 19:22
Bash script to parse JSON Web Tokens and pretty-print their contents
#!/bin/bash
# Parses JSON Web Tokens (https://en.wikipedia.org/wiki/JSON_Web_Token)
# and pretty-prints their content.
#
# © 2021 Daniel Lenski <dlenski@gmail.com>, MIT License
jq=$(which jq || echo cat)
for jwt in "$@"; do