Skip to content

Instantly share code, notes, and snippets.

@k01ek
k01ek / custom-log-filtering-and-formatting.py
Created January 13, 2022 11:27 — forked from acdha/custom-log-filtering-and-formatting.py
Example of how to filter or apply custom formatting using Python's logging library
#!/usr/bin/env python
# encoding: utf-8
from pprint import pformat, pprint
import logging
class PasswordMaskingFilter(logging.Filter):
"""Demonstrate how to filter sensitive data:"""
@k01ek
k01ek / asdot_and_asplain.py
Created August 26, 2021 13:56 — forked from lamoni/asdot_and_asplain.py
Convert 4 byte ASN (ASPLAIN) to ASDOT Notation and vice versa with Python
# e.g. Convert 4261160822 to 65020.10102
def convert_ASPLAIN_to_ASDOT(as_number):
if not(isinstance(as_number, int)) or as_number < 0 or as_number > 4294967295:
raise Exception('Invalid AS Number: must be int, must be greater than or equal to 0 and less than or equal to 4294967295')
return '{}.{}'.format(as_number // 65536, as_number % 65536)
# e.g. Convert 65020.10102 to 4261160822
def convert_ASDOT_to_ASPLAIN(as_dot_number):
if not(isinstance(as_dot_number, str)) or as_dot_number.count('.') != 1:
@k01ek
k01ek / setup.cfg
Created March 17, 2021 12:13 — forked from althonos/setup.cfg
A `setup.cfg` template for my Python projects
# https://gist.github.com/althonos/6914b896789d3f2078d1e6237642c35c
[metadata]
name = {name}
version = file: {name}/_version.txt
author = Martin Larralde
author-email = [email protected]
home-page = https://github.com/althonos/{name}
description = {description}
long-description = file: README.md
pip install -r requirements.txt
Requirement already satisfied: hvac==0.9.5 in ./venv/lib/python3.7/site-packages (from -r requirements.txt (line 1)) (0.9.5)
Collecting nornir==3.0.0
Downloading nornir-3.0.0-py3-none-any.whl (29 kB)
Requirement already satisfied: requests==2.22.0 in ./venv/lib/python3.7/site-packages (from -r requirements.txt (line 3)) (2.22.0)
Requirement already satisfied: genie==20.4.1 in ./venv/lib/python3.7/site-packages (from -r requirements.txt (line 4)) (20.4.1)
Requirement already satisfied: pyats in ./venv/lib/python3.7/site-packages (from -r requirements.txt (line 5)) (20.2.1)
Requirement already satisfied: py-zabbix==1.1.5 in ./venv/lib/python3.7/site-packages (from -r requirements.txt (line 6)) (1.1.5)
Requirement already satisfied: pytest==5.4.1 in ./venv/lib/python3.7/site-packages (from -r requirements.txt (line 7)) (5.4.1)
Requirement already satisfied: genie.libs.parser==20.4 in ./venv/lib/python3.7/site-packages (from -r requirements.txt (line 8)) (20.4)
@k01ek
k01ek / extract_data.py
Created December 14, 2020 07:32 — forked from bkaankuguoglu/extract_data.py
This program extracts regular expressions within the given frame on a set of documents.
#=======================================================================#
# extract_data.py #
#=======================================================================#
# usage: extract_data.py [-h] [-i INPUT_DIR] [-o OUTPUT_DIR]
#
# This program extracts provision numbers from a set of documents.
#
# optional arguments:
# -h, --help show this help message and exit
# -i INPUT_DIR, --input_dir INPUT_DIR
@k01ek
k01ek / README.md
Created February 26, 2020 11:01 — forked from nitaku/README.md
Minimal JSON HTTP server in python

A minimal HTTP server in python. It sends a JSON Hello World for GET requests, and echoes back JSON for POST requests.

python server.py 8009
Starting httpd on port 8009...
curl http://localhost:8009
{"received": "ok", "hello": "world"}
@k01ek
k01ek / LICENSE
Created September 20, 2019 12:28 — forked from mepcotterell/LICENSE
Simple Python Plugin Manager
The MIT License (MIT)
Copyright (c) 2013 Michael E. Cotterell
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@k01ek
k01ek / SOAPrequest.xml
Created July 31, 2019 10:57 — forked from lamprosg/SOAPrequest.xml
Tutorial - Example of a SOAP message (Web Services)
POST /InStock HTTP/1.1
Host: www.example.org
Content-Type: application/soap+xml; charset=utf-8
Content-Length: nnn
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
@k01ek
k01ek / telnet_websocket_proxy.py
Created July 16, 2019 13:36 — forked from night-crawler/telnet_websocket_proxy.py
A simple telnet-websocket proxy on python using Tornado. Tested with "Sphere of Worlds MUD". Replaces IAC and GA.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re
from tornado.web import RequestHandler, Application
from tornado.websocket import WebSocketHandler
from tornado.ioloop import IOLoop
import socket
import threading
import Queue
@k01ek
k01ek / ping.py
Created July 3, 2019 11:29 — forked from pklaus/ping.py
A pure python ping implementation using raw socket.
#!/usr/bin/env python2
"""
Other Repositories of python-ping
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* https://github.com/l4m3rx/python-ping supports Python2 and Python3
* https://bitbucket.org/delroth/python-ping