Skip to content

Instantly share code, notes, and snippets.

@mentha
mentha / 0USAGE
Last active November 6, 2022 03:35
libvirt hook to unlock bitlocker during windows boot
1. put bitunlocker.py in /etc/libvirt/hooks/qemu.d/
2. run bitunlocker.py to configure unlock keys
@mentha
mentha / unplug-pcidev.py
Last active November 6, 2022 01:37
hot unplug pci devices on linux
#!/usr/bin/env python3
from argparse import ArgumentParser
from contextlib import suppress
import logging
import os
import re
logger = logging.getLogger()
@mentha
mentha / ppua.py
Last active November 27, 2022 11:12
proxy protocol v2 universal adapter
#!/usr/bin/env python3
from argparse import ArgumentParser
from collections import namedtuple
from contextlib import AsyncExitStack
from ipaddress import IPv4Address, IPv6Address, IPv4Network, IPv6Network
from signal import signal, SIGHUP, SIGINT, SIGTERM
from socket import socket, AF_INET, AF_INET6, SOCK_STREAM, IPPROTO_IP, IP_TRANSPARENT, SHUT_WR
import asyncio as aio
import logging
@mentha
mentha / flatpak-auto-update.py
Last active September 9, 2022 15:52
flatpak auto update timer
#!/usr/bin/env python3
from argparse import ArgumentParser
from contextlib import suppress
from functools import cached_property
from sys import argv, exit, stderr
from time import time
import dbus
import os
import shlex
@mentha
mentha / dnf-plugin-remove-suid.spec.rpkg
Last active June 4, 2022 06:53
dnf plugin to remove setuid bits
%global descr DNF plugin to remove suid from packages
Name: dnf-plugin-remove-suid
Version: {{{ git_dir_version }}}
Release: 1%{?dist}
Summary: %{descr}
URL: https://gist.github.com/mentha/f02780b4889a2d03fbd9380ff33428d9
License: MIT
VCS: {{{ git_dir_vcs }}}
Source: {{{ git_dir_pack }}}
@mentha
mentha / oathupdate
Created May 3, 2022 13:39
manage pam_oath auth file
#!/usr/bin/env python3
# update OTP auth file of pam_oath
OATHFILE = '/etc/users.oath'
from base64 import b16encode, b16decode, b32encode
from sys import argv
import os
import subprocess as sp
@mentha
mentha / libvirt-assign-usb-port.py
Created May 3, 2022 13:36
assign a usb port to libvirt guest
#!/usr/bin/env python3
from argparse import ArgumentParser
from traceback import print_exc
import libvirt
import os
import re
import subprocess as sp
class PortForward:
@mentha
mentha / libvirt-assign-ip.py
Created May 3, 2022 13:35
assign static ip and network filters to libvirt guests
#!/usr/bin/env python3
from pprint import pprint
from argparse import ArgumentParser
from ipaddress import IPv4Address
from tempfile import NamedTemporaryFile
import libvirt
import os
import xml.etree.ElementTree as ET
@mentha
mentha / arp2wol.py
Created May 3, 2022 13:33
convert arp packets to wake-on-lan packets
#!/usr/bin/env python3
# Send wake-on-lan packets to targets of ARP packets
MAX_AGE = 86400 * 7
from sys import argv, stderr
from time import time
import os
import subprocess as sp
@mentha
mentha / aggregate.c
Created May 3, 2022 13:30
compress list of cidr
/* Compress CIDR list by aggregrating adjacent subnets. */
#define _POSIX_C_SOURCE 200809L
#include <arpa/inet.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>