Skip to content

Instantly share code, notes, and snippets.

🖥
.

Marius mkorthof

View GitHub Profile
@mkorthof
mkorthof / json2xml.py
Last active Feb 20, 2019
conv json to xml
View json2xml.py
#!/usr/bin/python3
# Source: https://github.com/quandyfactory/dicttoxml/blob/master/README.markdown
# page = urllib.urlopen('http://quandyfactory.com/api/example')
import json
import urllib
import dicttoxml
import sys
@mkorthof
mkorthof / clamwrap.sh
Created Jul 20, 2018
adjust clamscan oom score
View clamwrap.sh
#!/bin/sh
# http://www.oracle.com/technetwork/articles/servers-storage-dev/oom-killer-1911807.html
# https://backdrift.org/oom-killer-how-to-create-oom-exclusions-in-linux
echo 10 > /proc/self/oom_score_adj && /usr/bin/clamscan "$@"
@mkorthof
mkorthof / httpd.py
Last active Jun 12, 2018
Python SimpleHTTPServer
View httpd.py
# Moved to to its own repos: https://github.com/mkorthof/httpyd
@mkorthof
mkorthof / gist:e022f1643a7be0c3b75ce10be212162c
Created Jan 13, 2018
pop3.exp - connects to pop3 server using telnet
View pop3.exp
#!/usr/bin/expect
proc help {} {
global argv0
puts ""
puts "pop3.exp - connects to pop3 server using telnet"
puts ""
puts "usage: $argv0 <host> <user>"
puts " it will prompt for password"
puts ""
@mkorthof
mkorthof / csr.sh
Created Dec 29, 2017
Generate certificate request with SAN (needs file.key)
View csr.sh
#!/bin/bash
# ./csr.sh [domain] [filename] - generate certificate request (needs file.key)
# set domain and key/csr filename permanently:
DOMAIN="example.com"; FN="example"
# set certificate attributes:
C="AU"; ST="Some-State"; L="City"; O="Internet Widgits Pty Ltd"; OU="Section"
@mkorthof
mkorthof / .screenrc
Created Oct 25, 2017
alternative for screen + SSH_AUTH_SOCK
View .screenrc
# this needs an alias:
# alias screen='echo "setenv SSH_AUTH_SOCK $SSH_AUTH_SOCK" > $HOME/.ssh/screen; screen -X source $HOME/.ssh/screen; screen'
bind H eval "source $HOME/.ssh/screen" "readbuf $SSH_AUTH_SOCK" 'stuff "export SSH_AUTH_SOCK=$SSH_AUTH_SOCK\n"' "echo 'SSH_AUTH_SOCK set!'"
@mkorthof
mkorthof / ipset-logpat.sh
Last active Jan 18, 2018
creates ipset sets matching certain patterns in httpd logs
View ipset-logpat.sh
#!/bin/bash
# ipset-logpat
# searches httpd access logs for pattern, whoises matching ip's and uses
# ip blocks to create ipset set. also adds iptables rules to log and reject
# requires: iptables, ipset, aggregate (optional)
# other useful ipset commands: ipset list [-terse], ipset destroy
# more info:
@mkorthof
mkorthof / ipset-country
Last active Feb 20, 2019
Block countries using iptables + ipset + ipdeny.com
View ipset-country
#!/bin/sh
# ipset-country
# =============
# Block countries using iptables + ipset + ipdeny.com
# - run this script from cron, e.g. /etc/cron.daily
# - to run on boot you can also add it to e.g. /etc/rc.local
# NOTE: this script will insert an iptables REJECT rule for ipset
@mkorthof
mkorthof / vboxsave.bat
Created Aug 24, 2017
VirtualBox savestate all running VM's (Windows)
View vboxsave.bat
@echo off
:: https://superuser.com/questions/959567/virtualbox-windows-graceful-shutdown-of-guests-on-host-shutdown
SET "LOG=0"
SET "LOGFILE=%~dp0%vboxsave.log"
SET VBoxManage="%ProgramFiles%\Oracle\VirtualBox\VBoxManage.exe"
IF "%~1"=="LOG" ( SET "LOG=1" )
IF EXIST "%LOGFILE%.tmp" ( del %LOGFILE%.tmp )
IF %LOG% EQU 1 ( CALL :msg logging is enabled )
View uptime.cmd
@PowerShell -ExecutionPolicy RemoteSigned -Command Invoke-Expression $('$args=@(^&{$args} %*);'+[String]::Join(';',(Get-Content -LiteralPath '%~f0') -notmatch '^^@PowerShell.*EOF$')) & goto :EOF
$d = Get-Date
$upTime = (($d) - ([wmi]'').ConvertToDateTime((Get-WmiObject win32_operatingsystem).LastBootUpTime)).ToString("d' days, 'h\:mm")
$ActiveUsers = @()
foreach($User in (Get-WmiObject Win32_LoggedOnUser).Antecedent) { $ActiveUsers += $User.Substring($User.LastIndexOf('=') + 2, $User.Length - $User.LastIndexOf('=') -3) }
$UserText = "$($ActiveUsers.Count) user"
if ( $ActiveUsers.Count -gt 1 ) { $UserText += "s" }
$TotalProcTime = (Get-Counter "\Processor(_total)\% Processor Time") | foreach {$_.CounterSamples[0].CookedValue}
You can’t perform that action at this time.