Skip to content

Instantly share code, notes, and snippets.

@mpontillo
mpontillo / mc-get-latest
Last active March 4, 2020 17:45
bash script to grab the latest Minecraft server jars
#!/bin/bash -e
mkdir -p ~/var/lib/mc
MC_VERSIONS_CACHE="$HOME/var/lib/mc/version_manifest.json"
RELEASE_JSON="$HOME/var/lib/mc/_release.json"
SNAPSHOT_JSON="$HOME/var/lib/mc/_snapshot.json"
curl -sS https://launchermeta.mojang.com/mc/game/version_manifest.json > $MC_VERSIONS_CACHE
# cat $MC_VERSIONS_CACHE | jq
LATEST_SNAPSHOT=$(cat $MC_VERSIONS_CACHE | jq -r '{latest: .latest.snapshot} | .[]')
@mpontillo
mpontillo / lookup.py
Last active July 4, 2017 02:29
Look up the IP addresses and source interface for each given host.
#!/usr/bin/env python3
from collections import OrderedDict
import socket
import sys
def print_route_lookup(host, addrinfo):
endpoints = set()
for info in addrinfo:
@mpontillo
mpontillo / dnsperf_install.sh
Created May 30, 2017 17:47 — forked from hanshasselberg/dnsperf_install.sh
Install dnsperf on ubuntu
sudo apt-get install -y bind9utils libbind-dev libkrb5-dev libssl-dev libcap-dev libxml2-dev
curl ftp://ftp.nominum.com/pub/nominum/dnsperf/2.0.0.0/dnsperf-src-2.0.0.0-1.tar.gz -O
tar xfvz dnsperf-src-2.0.0.0-1.tar.gz
cd dnsperf-src-2.0.0.0-1
./configure
make
sudo make install
@mpontillo
mpontillo / y2j
Created May 30, 2017 17:42
Python script to input YAML and output "pretty" JSON.
#!/usr/bin/env python3
import sys
import json
import yaml
if __name__ == "__main__":
data = sys.stdin.read()
@mpontillo
mpontillo / markdown_doc
Last active May 26, 2017 20:04 — forked from jiffyclub/markdown_doc
This script turns Markdown into HTML using the Python markdown library and wraps the result in a complete HTML document with default Bootstrap styling so that it's immediately printable. Requires the python libraries jinja2, markdown, and mdx_smartypants.
#!/usr/bin/env python
import argparse
import sys
import jinja2
import markdown
# To install dependencies in a virtualenv:
# $ virtualenv ~/venv-markdown/
@mpontillo
mpontillo / get-vlans
Last active May 4, 2017 13:58
Get the list of VLAN interfaces and VIDs
#!/bin/bash
sudo cat /proc/net/vlan/config | tail -n +3 | sed 's/\W*|\W*/ /g' | sort -n -k 3,2
@mpontillo
mpontillo / get-dhcp-servers
Created April 27, 2017 21:16
Gets a list of DHCP servers based on the current running DHCP clients.
#!/bin/bash
ps auxwwww | grep dhclient | grep -o '\-lf .*' | awk '{ print $2 }' \
| xargs -n 1 grep -o 'dhcp-server-identifier [A-Za-z0-9\.:]*' 2> /dev/null \
| sort -u | awk '{ print $2 }'
@mpontillo
mpontillo / test-maas-enlistment.sh
Last active February 2, 2022 08:47
Script to fetch the default TFTP configuration from MAAS and fetch the cloud-config URL.
#!/bin/bash -e
TMPDIR="$(mktemp -d)"
function cleanup() {
rm -rf "$TMPDIR"
}
trap cleanup EXIT
#!/bin/bash -x
if ! iptables -t filter -L FORWARD | grep PORT_FORWARD; then
iptables -t filter -N PORT_FORWARD
iptables -t filter -I FORWARD -j PORT_FORWARD
fi
if ! iptables -t nat -L PREROUTING | grep PORT_FORWARD_DNAT; then
iptables -t nat -N PORT_FORWARD_DNAT
iptables -t nat -I PREROUTING -j PORT_FORWARD_DNAT
fi
@mpontillo
mpontillo / get_bmc_ips
Created March 28, 2017 01:26
Get all BMC IP addresses and which nodes use them from the MAAS database.
#!/bin/bash
cat << EOF | sudo -u postgres psql -P pager=off maasdb 2> /dev/null
SELECT
sip.ip "bmc_ip",
node.hostname AS "machine_hostname",
bmc.power_type
FROM maasserver_bmc bmc
LEFT OUTER JOIN maasserver_staticipaddress sip
ON sip.id = bmc.ip_address_id
LEFT OUTER JOIN maasserver_node node