Skip to content

Instantly share code, notes, and snippets.

@mrizvic
mrizvic / tcpdump-examples.sh
Last active April 26, 2020 19:29
userful tcpdump filters
### DHCP PACKETS FROM/TO CLIENT WITH MAC ADDRESS 7c:2f:80:22:58:fe
tcpdump -vve -l -nn -s0 -v -i eth1 'udp[36:4] == 0x7c2f8022 && udp[40:2] == 0x58fe'
### LCP OVER PPPOE PACKETS
### https://www.wireshark.org/lists/wireshark-users/200712/msg00182.html
tcpdump -ei enp1s0 pppoes and ppp proto 0xc021
### CDP PACKETS
### https://medium.com/@hybby/tcpdump-and-cdp-packets-a626364d5a2f
tcpdump -nn -v -i eth0 -s 1500 -c 1 'ether[20:2] == 0x2000'
@mrizvic
mrizvic / ifdiff.sh
Last active March 12, 2021 07:22
cat file if file content has changed from last run
#!/usr/bin/env bash
help_string="cat or diff file if content has changed from last run"
FILE=$1
ME=$(basename $0)
if [ -z "$FILE" ]; then
echo "USAGE: $ME <resultfile.txt>"
echo "EXAMPLE: ifdiff.sh /tmp/changing-file.txt - cat file when it was changed from previous run"
@mrizvic
mrizvic / sighandler.py
Created September 11, 2018 11:21
python signal handler template
#!/usr/bin/env python
import time
import signal
import sys
import datetime
import inspect
def signalhandler (signum, frame):

Keybase proof

I hereby claim:

  • I am mrizvic on github.
  • I am mrizvic (https://keybase.io/mrizvic) on keybase.
  • I have a public key ASDjoPvQ5ox-txhPJRPfq9xhEaK1DrZc6_LQs15tt1cx9go

To claim this, I am signing this object:

#!/bin/bash
### RUNNING:
#certbot certonly -d host.domain.tld --agree-tos --manual --preferred-challenges=dns --manual-auth-hook /root/certbot-hook-dns-auth.sh --manual-public-ip-logging-ok
HOST="_acme-challenge"
DYNZONE="SET_YOURDOMAIN_NAME"
if [ -z "$CERTBOT_DOMAIN" ] || [ -z "$CERTBOT_VALIDATION" ] || [ -z "$DYNZONE" ]
then
@mrizvic
mrizvic / nodemcu-pwm-fader.lua
Last active March 26, 2017 00:33
fadein-fadeout effect using PWM in nodeMCU LUA for use with ESPtoy for example
redPin = 2
greenPin = 1
bluePin = 4
pwm.setup(redPin,500,0)
pwm.setup(greenPin,500,0)
pwm.setup(bluePin,500,0)
pwm.start(redPin)
pwm.start(greenPin)
@mrizvic
mrizvic / nodemcu-ws2812-fader.lua
Last active March 22, 2017 09:25
fadein-fadeout effect on nodeMCU using WS2812 LED
-- nodeMCU specific
ws2812.init()
-- 4 LEDS, 3 bytes per LED
buffer = ws2812.newBuffer(4, 3)
green,red,blue = 255,64,192
buffer:fill(green,red,blue)
function brightness (x, max)
return math.floor((math.floor((x * max) / 100)*2) + 1)/2
end
@mrizvic
mrizvic / nodered-timestamp-properties.js
Last active October 23, 2022 18:00
Function for node-red which determines properties like holiday, business day, weekend, etc at the moment when incoming message is received. It contains Slovenian conditions to determine those properties.
/*
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* github.com/mrizvic wrote this file. As long as you retain this notice you
* can do whatever you want with this stuff. If we meet some day, and you think
* this stuff is worth it, you can buy me a beer in return. M.Rizvic
* ----------------------------------------------------------------------------
## This function will pass incoming message to multiple outputs based on following conditions:
@mrizvic
mrizvic / stdin2mail.sh
Created January 25, 2017 11:42
read from stdin and forward as HTML formatted mail
#!/usr/bin/env bash
ME=$(basename $0)
WORKFILE="/tmp/$ME.$$"
if [ ! -z "$MAILTO" ]; then
RCPT=$MAILTO
else
RCPT=$1
fi
@mrizvic
mrizvic / stats_cronjob.sh
Created January 19, 2017 11:28
cronjob for periodic report in HTML and cowsay format
#!/usr/bin/env bash
WORKFILE=/tmp/myreport.out
cat <<EOF > $WORKFILE
From: username <[email protected]>
To: [email protected]
Subject: your html report
Content-Type: text/html; charset="us-ascii"