Skip to content

Instantly share code, notes, and snippets.

View Gunni's full-sized avatar

Gunni Gunni

View GitHub Profile
@Gunni
Gunni / verify_redirects.py
Last active November 26, 2025 12:45
Useful to make sure HSTS works
#!/usr/bin/env python3
import sys
import socket
import ssl
import argparse
from urllib.parse import urlparse, urlunparse
import http.client
@Gunni
Gunni / .sh
Created November 6, 2025 13:59
Check compromised password oneliner
python3 -c 'import getpass ; import hashlib ; p = hashlib.sha1(getpass.getpass("Password to check: ").encode()).hexdigest().upper() ; print(f"Full hash: {p}\ncurl -s https://api.pwnedpasswords.com/range/{p[:5]} | grep {p[5:]} | grep \":\" || echo -n \"not \" ; echo compromised")'
@Gunni
Gunni / atomic_file.py
Created October 17, 2025 14:26
Python - Atomic file Reader/Writer
import os
import tempfile
from dataclasses import dataclass, field
from pathlib import Path
from typing import Any, IO, Type
class AtomicFile:
@dataclass(eq=False, kw_only=True)
class Reader:
@Gunni
Gunni / data_cleanup.sh
Last active June 19, 2025 10:39
SFTPgo user dir automatic cleanup
#!/bin/bash
IFS=$'\n\t'
set -euo pipefail
if [[ $EUID -eq 0 ]]; then
echo "This script must NOT be run as root" 1>&2
exit 1
fi
@Gunni
Gunni / get_systemd_services.py
Created May 4, 2023 18:46
How to get systemd service state via dbus in python
#!/usr/bin/env python3
from dataclasses import dataclass
from enum import Enum
from typing import List
from pystemd.systemd1 import Manager
@dataclass
class ServiceActiveState(str, Enum):
@Gunni
Gunni / sentry.inc.php
Created September 9, 2021 17:41
Observium integration for Sentry
<?php
// This file is silently disabled if not configured
if ( ! isset($config['sentry_dsn']))
{
return;
}
if (defined('SENTRY_LOADED'))
{
@Gunni
Gunni / helpers.py
Last active February 7, 2021 23:33
I hate number words
import re
import nltk as nltk
from word2number import w2n
def replaceTextnumberWithNumber(text):
#print(f'-- BEFORE --\n{text}')
tagged_number_words = 'ten/CD thousand/CD nine/CD hundred/CD ninety/CD eight/CD seven/CD six/CD five/CD four/CD three/CD two/CD one/CD eighty/CD seventy/CD sixty/CD fifty/CD forty/CD thirty/CD twenty/CD nineteen/CD eighteen/CD seventeen/CD sixteen/CD fifteen/CD fourteen/CD thirteen/CD twelve/CD eleven/CD zero/CD'
@Gunni
Gunni / output.txt
Last active April 21, 2020 15:01
RPKI Results, Iceland
Not found:
2603 192.36.171.0/24
2603 194.68.13.0/24
6677 31.209.144.0/20
6677 31.209.192.0/18
6677 85.220.0.0/17
6677 157.157.0.0/16
6677 192.147.34.0/24
6677 194.105.224.0/19
@Gunni
Gunni / nftables.conf
Last active November 14, 2025 12:42
Example nftables.conf for a wireguard "server"
table inet filter {
chain inbound {
type filter hook input priority 0
policy drop
ct state invalid counter drop
ct state { established, related } counter accept
ip protocol icmp counter accept
ip6 nexthdr ipv6-icmp counter accept
@Gunni
Gunni / ipv6allocations.py
Last active August 25, 2019 07:14
Just to show how huge IPv6 is
from collections import defaultdict
import requests
import csv
import ipaddress
import datetime
print(f'# {datetime.datetime.utcnow()}')
assignmentsFile = requests.get('https://www.iana.org/assignments/ipv6-unicast-address-assignments/ipv6-unicast-address-assignments.csv')
assignmentsFile.raise_for_status()