Skip to content

Instantly share code, notes, and snippets.

View alastairhm's full-sized avatar

Alastair Montgomery alastairhm

View GitHub Profile
@alastairhm
alastairhm / port_open.py
Created April 12, 2022 07:51
Check if port is open TCP/UDP in Python, zero result means connect is made.
def check_tcp(host,ip):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex((host,ip))
print(result)
sock.close()
def check_udp(host,ip):
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
result = sock.connect_ex((host,ip))
@alastairhm
alastairhm / snapshot_clean.sh
Created January 21, 2022 14:33
AWS CLI delete all but last five EBS snapshots with a certain name
#!/usr/bin/env bash
#
# Delete all but the last 5 snapshots with passed tag.
SNAPSHOTSID=$(aws ec2 describe-snapshots \
--owner-ids self \
--filters Name=tag:Name,Values="${1}" \
--query "Snapshots[*].{ID:SnapshotId}" --output text|tail +5)
for id in $SNAPSHOTSID; do
aws ec2 delete-snapshot --snapshot-id "$id"
@alastairhm
alastairhm / devops_learning_links.md
Last active December 9, 2021 16:33
DevOPs learning links
@alastairhm
alastairhm / check_versions.sh
Created November 1, 2021 14:21
Print out latest versions of TFSec, TFLint and TFDoc
#!/bin/bash
echo -n "TFsec : "
curl -s https://github.com/aquasecurity/tfsec/releases | grep "releases/tag"|awk 'NR<2 { split($0,a,">|<"); print a[5] }'
echo -n "TFLint : "
curl -s https://github.com/terraform-linters/tflint/releases | grep "/terraform-linters/tflint/releases/tag"|awk 'NR<2 { split($0,a,">|<"); print a[5] }'
echo -n "TFDoc : "
curl -s https://github.com/terraform-docs/terraform-docs/releases | grep "/terraform-docs/terraform-docs/releases/tag"|awk 'NR<2 { split($0,a,">|<"); print a[5] }'
/var/folders/6l/x0_g5lwn6qs493_6sfzwr3b80000gp/T/ruby-build.20210115092709.73250.yQfEKD ~
/var/folders/6l/x0_g5lwn6qs493_6sfzwr3b80000gp/T/ruby-build.20210115092709.73250.yQfEKD/ruby-2.7.2 /var/folders/6l/x0_g5lwn6qs493_6sfzwr3b80000gp/T/ruby-build.20210115092709.73250.yQfEKD ~
checking for ruby... /usr/bin/ruby
tool/config.guess already exists
tool/config.sub already exists
checking build system type... x86_64-apple-darwin19.6.0
checking host system type... x86_64-apple-darwin19.6.0
checking target system type... x86_64-apple-darwin19.6.0
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
@alastairhm
alastairhm / output.tf
Created January 12, 2021 08:40
Terraform extracting a list of values from a map of maps
variable "node_private_ips" {
default = {
"node1" = {
"az" = "eu-west-1a"
"fqdn" = "vadc-ext-pres-node1.ccoe-ch.aws-eu-west-1.dev.fred.plc"
"ip" = "100.77.254.5"
}
"node2" = {
"az" = "eu-west-1b"
"fqdn" = "vadc-ext-pres-node2.ccoe-ch.aws-eu-west-1.dev.fred.plc"
@alastairhm
alastairhm / error.txt
Created January 7, 2021 15:37
tfsec error report
$ tfsec
fatal error: runtime: out of memory
runtime stack:
runtime.throw(0x88a07d, 0x16)
/home/travis/.gimme/versions/go1.15.linux.amd64/src/runtime/panic.go:1116 +0x72
runtime.sysMap(0xc0b8000000, 0x4000000, 0xb7e858)
/home/travis/.gimme/versions/go1.15.linux.amd64/src/runtime/mem_linux.go:169 +0xc6
runtime.(*mheap).sysAlloc(0xb64940, 0x400000, 0x7fffffffffff, 0xc0b7ff6360)
/home/travis/.gimme/versions/go1.15.linux.amd64/src/runtime/malloc.go:727 +0x1e5
runtime.(*mheap).grow(0xb64940, 0x1, 0x0)
@alastairhm
alastairhm / install.sh
Created December 15, 2020 15:59
Python3 Pip Dependancies Ubuntu 18.04
wget http://archive.ubuntu.com/ubuntu/pool/main/p/python3-stdlib-extensions/python3-lib2to3_3.6.5-3_all.deb
sudo dpkg -i python3-lib2to3_3.6.5-3_all.deb
wget http://archive.ubuntu.com/ubuntu/pool/main/p/python3-stdlib-extensions/python3-distutils_3.6.5-3_all.deb
sudo dpkg -i python3-distutils_3.6.5-3_all.deb
wget http://archive.ubuntu.com/ubuntu/pool/universe/p/python-pip/python-pip-whl_9.0.1-2_all.deb
sudo dpkg -i python-pip-whl_9.0.1-2_all.deb
wget http://archive.ubuntu.com/ubuntu/pool/universe/p/python-pip/python3-pip_9.0.1-2_all.deb
sudo dpkg -i python3-pip_9.0.1-2_all.deb
@alastairhm
alastairhm / mode7_position.asm
Last active December 3, 2020 09:25
BBC Mode 7 character writes
\ Write characters to Mode 7 screen
\ Using Indirect Indexing
\ Using BeebASM assembler
oswrch = &FFEE
screen = &7C00
addr = &70
table = &80
ORG &2000
@alastairhm
alastairhm / thumbprint.py
Created December 2, 2020 13:24
Python Class to get CA thumbprint from the root certificate, useful for AWS OIDC EKS cluters providers.
import socket
import certifi
from OpenSSL import SSL
from eks_oidc.logger import Logger
logger = Logger(__name__).get_logger()
class ThumbNail: