Skip to content

Instantly share code, notes, and snippets.

View kimthostrup's full-sized avatar

Kim Thostrup kimthostrup

View GitHub Profile
@kimthostrup
kimthostrup / get-blocklist.sh
Created December 19, 2018 20:29
Ugly hack to download a couple of blocklist and use them in postfix
#!/bin/bash
# Go to our working directory
cd /tmp
# Download Blacklist
wget https://lists.blocklist.de/lists/all.txt --no-check-certificate
wget http://opendbl.net/lists/talos.list
# List cleaning
@kimthostrup
kimthostrup / delete_deny_rules.sh
Last active August 14, 2018 10:50
Delete all DENY rules from a UFW ruleset
sudo ufw status numbered | grep 'DENY IN' | awk -F] '{print $1}' | sed 's/\[\s*//' | tac | xargs -n 1 bash -c 'yes|sudo ufw delete $0
@kimthostrup
kimthostrup / disks_lshw.py
Created May 17, 2018 12:16 — forked from amitsaha/disks_lshw.py
Use lshw -xml to find the disk details
#!/usr/bin/env python
# Parse disk:* from lshw -xml
"""
Sample Output:
ATA Disk Hitachi HDS72105 /dev/sda
Disk Space: 500107862016
Sector size: 512
@kimthostrup
kimthostrup / connectbox-influx.py
Created May 14, 2018 18:51
Quick, dirty and crappy script to pull DOCSIS connection info from a UPC Connect Box (Compal CH7465LG) and push it to influxdb. Should run as a systemd service. Requires this: https://github.com/ties/compal_CH7465LG_py
#!/usr/bin/env python3
import argparse
import pprint
import os
import sys
import datetime
import signal
from time import sleep
from lxml import etree
@kimthostrup
kimthostrup / orwell.py
Created May 14, 2018 18:18 — forked from olf42/orwell.py
Fetches number of currently connected listeners from status.xml of icecast2 streaming server and pushes it to InfluxDB (at least v.0.10)
#!/usr/bin/env python3
import requests
import sys
import xml.etree.ElementTree as ET
import datetime
# ICECAST RELATED CONSTANTS
STATS_URL = "http://<URL>"
ICECAST_USER = "<USER>"
@kimthostrup
kimthostrup / xml.py
Created May 14, 2018 13:40
example for parsing xml
import xml.etree.ElementTree as ET
import urllib.request as MYURL
# tree = ET.parse('song.xml')
# rss = tree.getroot()
# for element in rss.findall('.channel/song'):
# print(element.attrib.get('sname'))
# print(element.findtext('title'))
# print(element.findtext('singer'))
kmaURL = "http://www.kma.go.kr/weather/forecast/mid-term-rss3.jsp?stnId=109"
@kimthostrup
kimthostrup / UFW_ban_country.md
Created January 19, 2018 22:04 — forked from jasonruyle/UFW_ban_country.md
UFW to block countries
#!/usr/local/bin/python
import os
import plivo
import sys
from time import strftime
if not os.path.isdir(PATH):
sys.exit()
#!/bin/bash
date=`date +%Y-%m-%d`
RETENTION_PERIOD="7"
HEADER="Backup data"
remove_oldfiles(){
echo "Removing directory $1 files older than $RETENTION_PERIOD days" | wall
find $1 -type f -mtime +$2 -exec rm '{}' \;
}
BACKUPDIR="/disk0/svn_backup/001/"
@kimthostrup
kimthostrup / nio.py
Created December 1, 2015 21:29 — forked from sobanvuex/nio.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
from os import listdir
import json
net = '/sys/class/net'
stat = net + '/{}/statistics/{}x_bytes'
interfaces = filter(lambda x: 'eth' in x, listdir(net))