Skip to content

Instantly share code, notes, and snippets.

View tg12's full-sized avatar
🏠
Working from home

tg12 tg12

🏠
Working from home
  • 36Hs6atY4XDwS8AK6qcSLtyVLCqX85fm1w
  • Earth
  • 15:11 (UTC +01:00)
  • LinkedIn in/jamessawyer12
View GitHub Profile
@tg12
tg12 / RouteOptima.ps1
Created March 7, 2024 19:51
A PowerShell script that identifies the interface with the default Internet route, sets it to the highest priority, and verifies connectivity by pinging Google.
# Identify the interface with the default route to the Internet (0.0.0.0 route)
$defaultRoute = Get-NetRoute -DestinationPrefix "0.0.0.0/0" | Sort-Object -Property RouteMetric | Select-Object -First 1
$interfaceIndex = $defaultRoute.InterfaceIndex
# Retrieve all network interfaces
$interfaces = Get-NetIPInterface -AddressFamily IPv4
# Set the priority for the interface with the default route to the highest (lowest metric)
foreach ($interface in $interfaces) {
if ($interface.InterfaceIndex -eq $interfaceIndex) {
@tg12
tg12 / Dockerfile Template
Created January 17, 2024 15:00
Dockerfile Template
# Use Python 3.12 slim image
FROM python:3.12.1-slim
# Set Environment Variables
ENV PYTHONUNBUFFERED=1 \
TZ=Europe/London
ENV PYTHONOPTIMIZE=TRUE
ENV PYTHONMALLOC=malloc
@tg12
tg12 / Markov_transition.py
Created January 16, 2018 12:00
Markov transition matrix in Python
#the following code takes a list such as
#[1,1,2,6,8,5,5,7,8,8,1,1,4,5,5,0,0,0,1,1,4,4,5,1,3,3,4,5,4,1,1]
#with states labeled as successive integers starting with 0
#and returns a transition matrix, M,
#where M[i][j] is the probability of transitioning from i to j
def transition_matrix(transitions):
n = 1+ max(transitions) #number of states
M = [[0]*n for _ in range(n)]
@tg12
tg12 / new_setup.sh
Last active May 20, 2022 21:09
New Install of Ubuntu or similar
apt update
apt upgrade -y
apt install linux-xanmod-edge -y
apt install glances htop nmap bleachbit git python3-pip iperf3 easy-rsa iptables-persistent tuned neofetch net-tools fail2ban ntpdate ntp ntpstat -y
service tuned start
tuned-adm list
tuned-adm profile throughput-performance
service tuned restart
apt autoclean -y
@tg12
tg12 / reddit_crosspost_bot.py
Last active July 5, 2021 10:10
Crosspost the best to the best on Reddit
import time
import praw
import sqlite3
from random import randint
from time import sleep
# FROMSUB = "cyber" # The subreddit you want to take posts from
# TOSUBS = ["cyber_security", "cyberlaws", "security", "privacy",
# "netsec", "technology", "computerforensics", "ComputerSecurity"] # The
# subreddits you want to post to
@tg12
tg12 / remove_expiredcerts.ps1
Created April 15, 2021 08:20
Remove all Expired Certs on a Windows Machine
# """THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
# NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE
# DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY,
# WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE."""
# Bitcoin Cash (BCH) qpz32c4lg7x7lnk9jg6qg7s4uavdce89myax5v5nuk
@tg12
tg12 / dscp-class ef
Created January 30, 2021 10:05
iptables -t mangle -A OUTPUT -p udp -j DSCP --set-dscp-class ef
iptables -t mangle -A OUTPUT -p udp -j DSCP --set-dscp-class ef
root@raspberrypi:~# iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
Chain INPUT (policy ACCEPT)
target prot opt source destination
@tg12
tg12 / firehol_iptables.sh
Last active March 7, 2020 15:43
If you are a masochist, Create iptables from ALL Firehol lists
#this may take a while, run with no hup and monitor the log
rm blocklist-ipsets/ -r
git clone https://github.com/firehol/blocklist-ipsets.git
cd blocklist-ipsets/
#We just want the IP's
grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}" *.ipset > merged-file
#We just want the unique IP's across the board
sort -u merged-file > merged-file_output
#Just the unique ips, iptables
for IP in $(cat merged-file_output | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b" | awk '{print $1}' | sort | uniq); do echo "Banning $IP"; iptables -A INPUT -s $IP/32 -d 0/0 -j DROP; iptables -A INPUT -s $IP/32 -d 0/0 -j LOG --log-prefix 'firehol-iptables-rule-js'; done
@tg12
tg12 / sysadmin_script.sh
Last active March 7, 2020 15:39
Ultimate Sysadmin Script, run on fresh install of Ubuntu
#!/bin/bash
#If possible, add something in for choosing [1] Configure Basics [2] Configure Security [3] Configure VMware Tools [4] Configure All. This might require Perl.
#set -x
#read -p "Configure this server to be on 192.168.1.3/24?" yn
#while true; do
#case $yn in
# [Yy]* )
# echo "What IP address will be assigned to this server?"
@tg12
tg12 / ftp_check.py
Last active August 27, 2019 19:51
Fast Multi-threaded FTP Scanner
from datetime import datetime
import time
import threading
###########################
from multiprocessing import Process
import random
###########################
import dns.resolver
import dns.reversename
import ftplib