Skip to content

Instantly share code, notes, and snippets.

@gustavorv86
gustavorv86 / iptables.conf
Last active September 7, 2022 12:05
Default iptables configuration.
#!/bin/bash
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A INPUT -i lo -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
@gustavorv86
gustavorv86 / logger.py
Last active January 4, 2023 09:44
Python3 logging example
import logging
import os
LOG_ENVIRON = "LOGLEVEL"
LOG_LEVEL_DEFAULT = logging.INFO
LOG_FILE = "/tmp/myapplication.log"
LOG_FORMAT = '%(asctime)-15s [%(levelname)s] %(message)s'
LOG_NAME = "myapplication"
@gustavorv86
gustavorv86 / systemd_simple.service
Created October 7, 2021 08:04
Systemd simple service unit file
[Unit]
Description=My service Daemon
After=network.target
[Service]
Type=simple
Restart=always
RestartSec=5
User=root
WorkingDirectory=/opt/myservice
@gustavorv86
gustavorv86 / argparse_example.py
Last active February 4, 2022 07:58
Python Argparse example
#!/usr/bin/env python3
import argparse
import sys
if __name__ == "__main__":
"""
Running examples:
@gustavorv86
gustavorv86 / br0.conf
Last active May 17, 2021 15:05
Mount bridge in Debian GNU/Linux to connect virtual machines
## /etc/network/interfaces.d/br0.conf
## Requirements: bridge-utils
## More info: https://wiki.debian.org/KVM
auto br0
iface br0 inet static
address 192.168.1.2
netmask 255.255.255.0
gateway 192.168.1.1
network 192.168.1.0
@gustavorv86
gustavorv86 / 10-persistent-net.link
Last active May 17, 2021 15:02
Change network interface name in Debian GNU/Linux 10 (buster)
@gustavorv86
gustavorv86 / exos-bash.py
Created April 29, 2021 08:26
Execute a BASH shell on EXOS Extreme Switches (aka ExtremeXOS)
#!/usr/bin/env python
#
# On EXOS shell create exos-bash.py.
#
# EXOS> edit script exos-bash.py
#
# Copy this entire content to exos-bash.py file.
#
##################################
@gustavorv86
gustavorv86 / openssl.cnf
Last active March 6, 2021 12:18
Create RootCA OpenSSL Self-Signed certificate from local web development applications.
## Run this command (change server01.domain.local from your server):
## openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -sha256 -config ./openssl.cnf -keyout /etc/ssl/private/server01.domain.local.key -out /etc/ssl/certs/server01.domain.local.crt
## Install the generated /etc/ssl/certs/server01.domain.local.crt on your computers and mobiles on Thrusted Root Certification Authorities store.
## Run this command to generate NGINX dhparam.
## openssl dhparam -out /etc/nginx/dhparam.pem 4096
[req]
distinguished_name = req_distinguished_name
@gustavorv86
gustavorv86 / all_network_adresses_from_ip_and_netmask.py
Last active December 7, 2020 16:46
Calculate all network IP adresses from a IP and a netmask
#!/usr/bin/env python3
import struct
import socket
def ip2int(addr):
return struct.unpack("!I", socket.inet_aton(addr))[0]
@gustavorv86
gustavorv86 / rest-time.py
Last active February 16, 2020 22:17
Pythonic Rest time service using Flask
#!/usr/bin/env python3
#
# REQUIREMENTS
#
# Flask-RESTful 0.3.8
# pyOpenSSL 19.1.0
#
import datetime
import time