Skip to content

Instantly share code, notes, and snippets.

@chrisdlangton
chrisdlangton / get_lonlat.sh
Created April 21, 2017 02:56
Postcode in MySQL to Lat Lon script
#!/usr/bin/env bash
user=root
password=admin
result=$(mysql melbdatathon2017 -hmysql -u $user -p$password<<<"SELECT DISTINCT postcode FROM stores")
post_code_list=(`echo ${result}`)
delete=(postcode)
array=( "${post_code_list[@]/$delete}" )
for post_code in "${array[@]}"
@chrisdlangton
chrisdlangton / aws-s3-sync.sh
Last active August 22, 2017 06:51
Network Tap monitoring
#!/usr/bin/env bash
AWS=/home/`whoami`/.local/bin/aws
DATE=`date "+%Y%m%d-%H"`
BUCKET=<change me>
AWS_PROFILE=<change me>
BACKUPDIR=/mnt/share/backup/tshark/
TMPDIR=/tmp/${DATE}/
@chrisdlangton
chrisdlangton / Dockerfile
Created October 25, 2017 09:16
AWS Lambda Node.js 6.10 Dockerfile
FROM node:6.10
RUN mkdir -p /var/task
WORKDIR /var/task
RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
apt-get upgrade -y && \
apt-get install -y --no-install-recommends build-essential g++ python2.7 python2.7-dev unzip zip curl wget && \
apt-get autoremove -y && \
rm -rf /var/lib/apt/lists/* && \
@chrisdlangton
chrisdlangton / rc.local
Last active January 4, 2019 12:41
Baked Ghost.io Blog for AWS Ubuntu 16.04 EC2 instance for RDS MySQL
#!/bin/bash -ex
exec > >(tee /var/log/rc.local.log|logger -t rc.local -s 2>/dev/console) 2>&1
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
@chrisdlangton
chrisdlangton / slack-post.sh
Created November 16, 2017 03:26
Simple slack post via Incoming WebHooks
#!/usr/bin/env bash
# Usage: date | ./slack-post.sh
# Usage: echo "Hello Word" | ./slack-post.sh
webhook_url=https://hooks.slack.com/services/...
while read LINE; do
text="$text\n$LINE"
done
@chrisdlangton
chrisdlangton / scanner.py
Created November 17, 2017 23:32
Nmap host port scanner in Python
#!/usr/bin/env python
###########################
# pip install python-nmap
# usage:
# ./scanner.py -i 59.x.x.x
# This will take a while, press 's' on the keyboard to
# see the elapsed time (and know it's still running the scan)
import nmap
import argparse
import termios, fcntl, sys, os
@chrisdlangton
chrisdlangton / collect-ip-info.py
Created November 17, 2017 23:37
Python script to enrich data about IP hosts from csv file
#!/usr/bin/env python
#########################################
# pip install pandas ipwhois
# usage:
# ./collect-ip-info.py
# Place a csv in same directory and change name of file_in variable
# First csv row is header, followed by a single ip per row
# Make sure you put your own google maps api key below
import csv
import requests
@chrisdlangton
chrisdlangton / compute-internet-connected-ip.py
Created November 18, 2017 00:49
Generate csv list of IPs that are internet connected with Python
#!/usr/bin/env python
##################################
# pip install netaddr
from netaddr import IPAddress, IPNetwork
file_out = "./internet-connected.csv"
with open(file_out, mode='a+') as f:
for class_a in range(0, 255):
a = IPAddress("%s.0.0.0" % class_a)
if not a.is_reserved():
@chrisdlangton
chrisdlangton / monitor.sh
Created February 24, 2018 12:25
site monitor
#!/usr/bin/env bash
# script to check website status (online/ofline)
while read site
do
if wget -p "$site" -O /dev/null &>/dev/null; then
echo "$site is up"
else
# action to do if website offline
echo "[$(date +%d-%m-%Y:%H:%M:%S)] $site is not reachable." | ./slack-post.sh
@chrisdlangton
chrisdlangton / cpu-temp.sh
Created March 4, 2018 01:24
CPU temperature logged to systemd log
#!/usr/bin/env bash
set -o errexit
systemd-cat -t "cpu-temp" \
echo "CPU `sensors | grep "CPU Temperature" | sed -e 's/[^0-9]/ /g' -e 's/^ *//g' -e 's/ *$//g' | tr -s ' ' | sed 's/ /\n/g' | head -n1 | xargs`°C"
exit 0