Skip to content

Instantly share code, notes, and snippets.

View craSH's full-sized avatar

Ian Gallagher craSH

View GitHub Profile
#!/usr/bin/env bash
function ssh-keygen-remove-all() {
if [ -n $1 ]; then
ssh-keygen -R "$1" >/dev/null 2>&1 && \
echo "Removed complete hostname: $1"
simple_host=$(echo $1 | cut -d '.' -f1)
if [ -n "$simple_host" ]; then
ssh-keygen -R "$simple_host" >/dev/null 2>&1 && \
@craSH
craSH / ssh-mkkey
Last active March 2, 2020 21:13
Handy helper script to generate new SSH keys in a predictable format, provide the needed ssh_config stanza to use them, and automatically upload them to the remote server.
#!/usr/bin/env bash
#
# Handy helper script to generate new SSH keys in a predictable format,
# provide the needed ssh_config stanza to use them, and automatically
# upload them to the remote server.
#
# Copyleft 2014 Ian Gallagher <crash@neg9.org>
if [ -z "$1" ]; then
echo "Usage: $0 <remote_host> [key_type] [key_size]" >&2
@craSH
craSH / iptables-sol.sh
Last active September 4, 2018 18:23
Masquerade/redirect incoming TCP connections on all ports (1:65535) to $dst_ip port $dst_port.Great for creating a proxy/jump box that lets you SSH to your server, in cases when you're on strange/(poorly) restrictive networks and need to tunnel out.
#!/bin/bash
#
# Masquerade/redirect incoming TCP connections on all ports (1:65535) to $dst_ip port $dst_port
# Call with -f to force update, even if IP cache exists and shows no changes.
# Make sure this isn't a CNAME! Otherwise the below dig command won't follow it and return an IP.
dst_host="neg9.org"
target_ns="google-public-dns-a.google.com"
dst_port=22
@craSH
craSH / diceware.py
Last active April 28, 2017 17:44
Select easy to use passphrases based on the diceware list; but not their selection methodology [lazy]
#!/usr/bin/env python
"""
Select easy to use passphrases based on the diceware list; but not their selection methodology [lazy].
Place the diceware and beale wordlists (GPG signed is fine) in /usr/share/dict before use.
* Diceware list: http://world.std.com/~reinhold/diceware.wordlist.asc
* Alternative Beale list: http://world.std.com/~reinhold/beale.wordlist.asc
* EFF List (Large): https://www.eff.org/files/2016/07/18/eff_large_wordlist.txt
* EFF List (Small): https://www.eff.org/files/2016/09/08/eff_short_wordlist_1.txt
@craSH
craSH / tc_to_kml.py
Created March 14, 2017 09:58
tripcreator-manipulator
#!/usr/bin/env python
"""
Parse a TripCreator JSON file and emit a KML file.
Example: https://widgets.tripcreator.com/gas-stations-prices-iceland-map/tripcreator-gas-prices-iceland.json
Taken from the widget on this page: http://luxeadventuretraveler.com/tips-for-driving-icelands-ring-road-winter/
Copyleft 2017 Ian Gallagher <crash@neg9.org>
"""
import json
import os
@craSH
craSH / init-tunnels.sh
Last active June 3, 2016 08:17
Script to setup multiple SSH tunnels in a reliable way for use with FoxyProxy or other SOCKS-aware clients
#!/usr/bin/env bash
#
# Use to setup numerous various tunnels to SSH servers, useful with ssh config blocks like those below
# for each host, with incrementing port numbers for each - then configure FoxyProxy etc to use the unique
# port for each host you want to tunnel out of.
#
# Thanks to tecknicaltom <tecknicaltom@neg9.org> for the initial idea behind tying this all together.
#
# Host host_alpha
# IdentityFile ~/.ssh/id_ecdsa-$USER-host_alpha-<remote_hostname>-<key_gen_year>-<key_gen_month>
@craSH
craSH / hashpromptshort.sh
Created April 24, 2010 07:02
color your prompt based roughly (1/8*2 hashing) on hostname -f output. Also strip vowels from hostname to give a shorter prompt.
if [ "$PS1" ]; then
if [ "$BASH" ]; then
shortname=${HOSTNAME%%.*}
shortname=${shortname//[aeiou]/}
hostname_crc=$(echo $HOSTNAME | tr 'A-Z' 'a-z' | cksum)
hostname_crc=${hostname_crc%% *}
hostcolor_a=$(( (0x${hostname_crc} + 1) % 2 ))
hostcolor_b=$(( 0x${hostname_crc} % 8 + 30 ))
PS1="\[\e[33;1m\]\u@\[\e[${hostcolor_a};${hostcolor_b}m\]${shortname}:\[\e[0m\]\w"'\$ '
PS2='\[\e[31;1m\]>\[\e[0m\]'
@craSH
craSH / plflip
Created November 22, 2013 21:31
Convert given plist file in-place from binary to XML or XML/JSON to binary.
#!/bin/bash
# Convert given plist file in-place from binary to XML or XML to binary.
file -bI "$1" | grep -q '^application/octet-stream'
if [ $? -eq 0 ]; then
# Binary plist - convert to XML
plutil -convert xml1 "$1" || echo "Failed to convert $1 to XML." >&2; exit 1
echo "Converted to XML: $1"
@craSH
craSH / splitm3u.py
Last active December 14, 2015 15:49
Add support for creating pls format playlists in addition to m3u
#!/usr/bin/env python
"""
Tiny script to split M3U playlist entries from stdin out to multiple playlists.
Handy for iTunes, because it's stupid in how it imports playlists.
Copyleft 2011 Ian Gallagher <crash@neg9.org>
"""
import sys, os
def do_stdin():
pls = False
@craSH
craSH / pbkdf2.java
Created June 15, 2012 19:35
Java PBKDF2 method + string wrapper, relies on some external methods for converting to hex strings.
public String hashPassword(String password, String salt) throws Exception
/*
* Wrap pbkdf2 method to return password hash as a hex string
*/
{
// Bail if password or salt are null/0 length
if ((null == password || 0 == password.length()) || (null == salt || 0 == salt.length()))
throw new Exception("Failed to create PBKDF2 Hash for password, password or salt can not be empty");
// Result string