Skip to content

Instantly share code, notes, and snippets.

@Red5d
Red5d / iplookup
Created January 3, 2014 05:21
Use this to look up the Country, State, City, ISP, and Hostname of an IP address (given as parameter) from infosniper.net. Usage: ./iplookup <ip address>
#! /bin/bash
info=$(curl -s http://www.infosniper.net/?ip_address=$1 | grep content-td2 | cut -d'>' -f2 | cut -d'<' -f1 | sed 's/&nbsp;//g')
echo -n "Country: "
echo "$info" | sed -n '10p'
echo -n "State: "
echo "$info" | sed -n '6p'
@Red5d
Red5d / geoip-restrict
Created February 18, 2014 02:52
This script helps set up GeoIP-based access restriction.
#! /bin/bash
# This script helps set up GeoIP-based access restriction.
# Commands adapted from http://blog.grimneko.de/?p=228
echo "Installing libgeoip-dev, libpam0g-dev, and make (just in case it's not there)..."
sudo apt-get install libgeoip-dev libpam0g-dev make
echo
@Red5d
Red5d / security-setup
Last active August 29, 2015 13:56
Setup basic security for a new server.
#! /bin/bash
echo "Installing basic security..."
apt-get -y install ufw rkhunter fail2ban
ufw allow 22
ufw allow 80
ufw allow 443
ufw enable
# Scan network range (replace with yours) for MAC addresses, compare with previous scan, and report differences with PushBullet.
# Requires pushbullet bash script from https://github.com/Red5d/pushbullet-bash
touch prev-macs.txt
sudo nmap -sP -n 192.168.1.1/24 | grep "MAC Address" | sort > macs.txt
if [ $(diff macs.txt prev-macs.txt) ];then
pushbullet push all note "New network devices: $(diff macs.txt prev-macs.txt)"
fi
mv macs.txt prev-macs.txt
function mempercent {
total=$(free -m | sed -n '2p' | awk '{print $2}')
used=$(free -m | sed -n '3p' | awk '{print $4}')
echo $(echo $(echo 'scale=2;'$used'/'$total'' | bc)*100 | bc | cut -d'.' -f1)"% memory usage (${used}M Used / ${total}M Total)"
}
function systemload {
loadAverage=$(uptime | cut -d',' -f4 | grep -o "[0-9]*\.[0-9]*$")
processors=$(cat /proc/cpuinfo | grep processor | tail -n1 | awk '{ print $3 }')
let processors=$processors+1
#! /bin/bash
# Author: Red5d
# Commands adapted from: https://www.digitalocean.com/community/tutorials/how-to-install-an-ssl-certificate-from-a-commercial-certificate-authority
if [ $(which openssl) -eq "" ];then
echo "Can't find openssl command. Exiting..."
exit 1
fi

Keybase proof

I hereby claim:

  • I am red5d on github.
  • I am red5d (https://keybase.io/red5d) on keybase.
  • I have a public key whose fingerprint is 2CB6 B1AA AD59 0C00 7226 33E7 C9A4 29E2 A9F7 EF57

To claim this, I am signing this object:

@Red5d
Red5d / pbis
Created March 26, 2015 15:22
Ansible module to manage the PBIS config
#! /usr/bin/env python
# Author: Red5d
# Date: 8/11/2014
#
# Description: Ansible module to manage the PBIS config.
#
# Examples:
#
# Get all current PBIS config settings and put them into the pbis_output variable:
@Red5d
Red5d / memegen
Created July 14, 2015 21:41
CLI python tool for using the http://memegen.link/ meme generator service.
#! /usr/bin/env python
# Author: Red5d
# Client tool for the http://memegen.link/ service.
# Run with no parameters for help.
import json, sys, urllib
if len(sys.argv) < 2:
@Red5d
Red5d / dockerps
Last active March 14, 2018 03:12
Python version of the "docker ps" command that rearranges the output to fit on a smaller terminal window a little better.
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from docker import Client
import sys
reload(sys)
sys.setdefaultencoding('utf8')
c = Client(base_url='unix://var/run/docker.sock')