Skip to content

Instantly share code, notes, and snippets.

View mjuenema's full-sized avatar

Markus Juenemann mjuenema

View GitHub Profile
@mjuenema
mjuenema / getpass.md
Created February 20, 2018 01:31
Python password input

I tried many different getpass style packages but they either didn't install properly or would't work. The code below has been adapted from getpass3. It requires the getch package and only runs under Python 3.

#/usr/bin/env python3

from getch import *
import sys

echo = '*'
@mjuenema
mjuenema / enterprise-numbers2json.py
Created April 11, 2018 01:32
Convert IANA Enterprise Numbers to JSON
#!/usr/bin/env python
# Convert IANA Enterprise Numbers to JSON
#
# TODO: Deal with "misformatted" lines in input better.
#
# (c) 2018 Markus Juenemann <markus&juenemann.net>
import json
import urllib
@mjuenema
mjuenema / sysdescr2os.py
Created April 11, 2018 07:34
Map SNMPv2::sysDescr.0 to ansible_network_os (or any other OS tag)
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
DOCUMENTATION = """
lookup: sysdescr2os
author: Markus Juenemann <[email protected]>
version_added: "2.5"
short_description: Derive OS from SNMPv2::sysDescr.0
description:
- "Derive the OS from the SNMPv2::sysDescr.0. This lookup is meant ot be used in combination

Syslog server in Python

Very basic Syslog server in Python that accepts messages in RFC3164 and RFC5424 format. This has only been tested with Rsyslog on Linux and Cisco IOS syslog. Other implementations may send mesages in slightly different format than the two regular expressions at the top of the script will match. In particular there are apparently many implementations that deviate from strict RFC3164.

from __future__ import print_function
import re
@mjuenema
mjuenema / traphandle.md
Last active November 5, 2021 21:16
Example net-snmp/snmptrapd traphandle

Example net-snmp/snmptrapd traphandle

#!/usr/bin/python3
  
"""Example net-snmp/snmptrapd traphandle.

     snmptrapd -a -c snmptrapd.conf -Obs -t -X

     # snmptrapd.conf
@mjuenema
mjuenema / downloading_python_packages.md
Last active July 12, 2020 16:42
Downloading Python Packages

Instructions for downloading Python packages for installation on a different host.

  1. Start a shell inside a CentOS/7 (or any other system) Docker Container with the exact version of Python that is installed on the other host.
mkdir /tmp/python-package
cd /tmp/python-package
docker run -i -t --rm --entrypoint /bin/bash -v `pwd`:/work python:3.7.0-centos7
  1. Install and upgrade pip3 (if it doesn't already exist)