Skip to content

Instantly share code, notes, and snippets.

View chalvorson's full-sized avatar

Carl Halvorson chalvorson

  • United States
View GitHub Profile
@chalvorson
chalvorson / deb12vaultwardenInstall.md
Last active June 22, 2024 00:36
Debian 12 Vaultwarden install (no docker)
@chalvorson
chalvorson / ip_address.py
Created May 14, 2023 01:51
IP Address class for better sorting than strings. Partially written by Google Bard.
class IPAddress:
def __init__(self, address):
self.octets = address.split(".")
for i in range(len(self.octets)):
self.octets[i] = int(self.octets[i])
def __str__(self) -> str:
return ".".join([str(octet) for octet in self.octets])
def __repr__(self) -> str:
@chalvorson
chalvorson / saferdata.py
Created November 6, 2022 02:31
Helper functions for the Cryptography library
import base64
import os
import time
from cryptography.fernet import Fernet
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
"""
Requires the cryptography library. At the moment cryptography is at version 38.0.3
@chalvorson
chalvorson / http_my_ip.py
Created November 5, 2022 22:09
Simple "What's my IP" server
import argparse
import socket
from http.server import BaseHTTPRequestHandler, HTTPServer
server_port = 9000
hostname = socket.gethostname()
local_ip = socket.gethostbyname(hostname)
class IPServer(BaseHTTPRequestHandler):
@chalvorson
chalvorson / personal-signing-certificate.txt
Created November 5, 2022 21:57
Create code-signing certificate to sign Windows executable
Notes to create a personal code-signing certificate. Assumes that Easy-RSA is already set up as Certificate Authority.
Tools used:
OpenSSL
Easy-RSA
signtool.exe (winget install Microsoft.WindowsSDK)
Using OpenSSL:
Generate a key and a certificate signing request
@chalvorson
chalvorson / mapper.py
Created August 27, 2021 21:44
Map a network share as the current logged-on user
import win32wnet, win32netcon
from impersonate import ImpersonateUser
with ImpersonateUser():
# map the drive using the current user's login
try:
nr = win32wnet.NETRESOURCE()
nr.dwScope = win32netcon.RESOURCE_GLOBALNET
nr.dwType = win32netcon.RESOURCETYPE_DISK
nr.dwUsage = win32netcon.RESOURCEUSAGE_CONNECTABLE
@chalvorson
chalvorson / impersonate.py
Created August 27, 2021 21:35
Simple context manager for impersonating the current logged-in user under Windows OS.
"""Simple context manager for impersonating the current logged-in user
under Windows OS.
Requires:
pywin32
"""
import ctypes
from win32process import GetWindowThreadProcessId
from win32api import OpenProcess
@chalvorson
chalvorson / motd.sh
Created July 3, 2020 05:48
Custom Raspberry Pi MOTD
#!/bin/bash
let upSeconds="$(/usr/bin/cut -d. -f1 /proc/uptime)"
let secs=$((${upSeconds}%60))
let mins=$((${upSeconds}/60%60))
let hours=$((${upSeconds}/3600%24))
let days=$((${upSeconds}/86400))
UPTIME=`printf "%d days, %02dh%02dm%02ds" "$days" "$hours" "$mins" "$secs"`
# get the load averages
@chalvorson
chalvorson / WSUS-ApproveUpdatesFromFile.ps1
Created March 5, 2020 02:48
Approve list of updates for computer group on WSUS
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true,
Position=0)]
[string]
$WsusServer,
[int]
$Port = "80",
[Parameter(Mandatory=$true)]
[ValidateScript({Test-Path $_ -PathType 'Leaf'})]
@chalvorson
chalvorson / cisco_ios_backup.py
Created December 8, 2019 22:16
Backup running configuration of a list of Cisco IOS switches
'''
This script uses netmiko to take a backup from cisco ios switches. The config files
are stored in config/ and the log files are stored in log/
Arguments: -u - login username
-p - login password
-s - enable password
-f - file with list of switch ip addresses
Output is an .ios file for each switch with date stamp
Requirements: netmiko, loguru