Skip to content

Instantly share code, notes, and snippets.

@Pr1meSuspec7
Pr1meSuspec7 / check_if_ipv4.py
Last active February 19, 2021 20:59
Function for check if input is an ipv4 address.
def check_if_ipv4(ip):
quad = ip.split(".")
quadinteger = []
try:
quadinteger = [int(num) for num in quad]
except ValueError:
#print('ERROR: Must be an ipv4 address')
return
while len(quadinteger) != 4:
#print('ERROR: Must be four octects')
@Pr1meSuspec7
Pr1meSuspec7 / pkg_requirement.py
Last active April 1, 2020 18:02
Fucntion to check and install missing packages
import re
import sys
import subprocess
def pkg_requirement(*pkgs):
output = subprocess.check_output((['pip', 'list']))
outputDecode = output.decode("utf-8")
#print(outputDecode)
pipList = re.split(r'\s', outputDecode)
pipNeed = []
@Pr1meSuspec7
Pr1meSuspec7 / colortext.py
Created April 1, 2020 18:01
Simple colorize output
COLORS = {'grey': 30, 'red': 31, 'green': 32, 'yellow': 33, 'blue': 34, 'magenta': 35, 'cyan': 36, 'white': 37}
RESET = '\033[0m'
def colortext(text, color=None):
# Ex: print(colortext('some text', 'cyan'))
ascii_color = '\033[1;%dm%s'
if color is not None:
text = ascii_color % (COLORS[color], text)
@Pr1meSuspec7
Pr1meSuspec7 / Monokai.sublime-color-scheme
Created March 5, 2024 13:42
Sublime Text 4.x | Color settings for "Compare Side-By-Side" package
// Correct color/scope for "Compare Side-By-Side" plugin
// Install: Preferences > Customize Color Scheme > paste this on the right side > save
// Documentation at https://www.sublimetext.com/docs/color_schemes.html
{
"variables":
{
},
"globals":
{
@Pr1meSuspec7
Pr1meSuspec7 / noroot_tcpdump.sh
Created March 13, 2024 08:08
EVE-NG | PNETLAB | TCPDUMP | Enable no-root users to run packet capture
#!/usr/bin/env bash
# This will let anyone who belongs to the 'pcap' group
# execute 'tcpdump'
sudo groupadd pcap
sudo usermod -a -G pcap $USER
sudo chgrp pcap /usr/sbin/tcpdump
sudo setcap cap_net_raw,cap_net_admin=eip /usr/sbin/tcpdump
sudo ln -s /usr/sbin/tcpdump /usr/bin/tcpdump
@Pr1meSuspec7
Pr1meSuspec7 / netmiko_exception.py
Created May 16, 2024 09:39
NETMIKO | Manage TimeoutException and AuthenticationException
#https://pyneng.readthedocs.io/en/latest/book/18_ssh_telnet/netmiko.html
from pprint import pprint
import yaml
import netmiko
def send_show_command(device, commands):
result = {}
try:
@Pr1meSuspec7
Pr1meSuspec7 / .bash_aliases
Created May 20, 2024 13:18
Linux aliases
alias python='python3.11'
alias mv='mv -v'
alias rm='rm -v'
alias cp='cp -v'
alias ping='ping -O'
alias play='ansible-playbook'
alias playsec='ansible-playbook --vault-password-file secrets.txt'
alias tf='terraform'
alias tfp='terraform plan'
alias tfa='terraform apply'
@Pr1meSuspec7
Pr1meSuspec7 / output.yml
Created June 4, 2024 21:11
Ansible loop output in one file
- name: Save output
ansible.builtin.copy:
content: |-
{% for host in ansible_play_hosts_all %}
{{ '### ' }}{{ host }}{{ ' ###' }}
{{ hostvars[host]['result']['stdout_lines'] | to_nice_json }}
{% endfor %}
dest: output.log
mode: "0644"
@Pr1meSuspec7
Pr1meSuspec7 / typewriter.py
Created June 25, 2024 17:05
Function to simulate typewriter
import sys, time
def typewriter(text):
for character in text:
sys.stdout.write(character)
sys.stdout.flush()
time.sleep(0.008)
print("\n")