Skip to content

Instantly share code, notes, and snippets.

View Gunni's full-sized avatar

Gunnar Guðvarðarson Gunni

View GitHub Profile
@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
Created February 26, 2020 23:12
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()
@Gunni
Gunni / .py
Created July 19, 2019 18:43
python sha512 using mmap
# Switch sha512 out for any other if you want
# Use hexdigest if you want a "normal" hex version of the digest
def hashFile(path):
with open(path, 'r') as fh, mmap.mmap(fh.fileno(), 0, prot=mmap.PROT_READ) as map:
return hashlib.sha512(map).digest()
@Gunni
Gunni / wgp.py
Last active June 28, 2019 00:14
Wireguard prettifier
#!/usr/bin/python3
'''
The script looks for a line similar to:
PublicKey=eP5bTA845m1hTnp0bjgFnw4efn+NHQ7WrXVwVmffwhY=
Then it goes back one line and uses that if it is a comment
# Example comment
Example file content
<?php
define(LDAP_OPT_DIAGNOSTIC_MESSAGE, 0x0032);
$handle = ldap_connect('ldap://9.0.0.1');
$bind = ldap_bind($handle, 'observium-xxxxx@domain.local', 'super good password');
if ( ! $bind)
{
if (ldap_get_option($handle, LDAP_OPT_DIAGNOSTIC_MESSAGE, $extended_error))
@Gunni
Gunni / client-cert.inc.php
Created March 2, 2017 23:05
html/includes/authentication/client-cert.inc.php
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage authentication
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited