Skip to content

Instantly share code, notes, and snippets.

@tjt263
tjt263 / Random Bash Functions
Created June 24, 2016 12:49 — forked from mmstick/Random Bash Functions
Simply a collection of bash functions/scripts that I don't particularly have a practical use for, but decided to make them since I was bored anyway. Feel free to put them in your bash_aliases file.
#!/bin/bash
function package-version {
apt-cache policy $1 | grep Installed | awk -F ' ' '{print $2}'
}
function kernel-current-version {
major=$(uname -r | awk -F '.' '{print $1}')
minor=$(uname -r | awk -F '.' '{print $2}')
if [ $(uname -r | grep rc) ]; then
rc="rc$(uname -r | awk -F '-' '{print $2}' | awk -F 'rc' '{print $2}')"
@tjt263
tjt263 / template-getopts.sh
Last active May 12, 2016 18:29
This script is an example of how to use getopts in a shell script. It is intended as a reference for demonstration purposes. Feel free to use it as a style template in scripts of your own.
#!/bin/bash
while getopts "h" opt; do
case $opt in
h ) echo "usage: $0 [-h]";
echo "this is just a style template.";
exit 0
;;
esac
done
#!/usr/bin/env python
import sys
import socket
import getopt
import threading
import subprocess
# define some global variables
#!/usr/bin/env python
import socket
target_host = raw_input("target host: ")
target_port = int(raw_input("target port: "))
# create a socket object
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#!/usr/bin/env python
import socket
import threading
bind_ip = raw_input("bind ip: ")
bind_port = int(raw_input("bind port: "))
# create a socket object
server = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
#!/usr/bin/python
import socket
import threading
bind_ip = "0.0.0.0"
bind_port = 9999
# create a socket object
server = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
#!/usr/bin/python
import socket
target_host = raw_input("target host: ")
target_port = int(raw_input("target port: "))
# create a socket object
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
#!/usr/bin/env python
import socket
target_host = raw_input("target host: ")
target_port = int(raw_input("target port: "))
# create a socket object
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#!/usr/bin/python
import socket
target_host = "www.google.com"
target_port = 80
# create a socket object
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@tjt263
tjt263 / _testLoops.sh
Last active June 19, 2016 08:31
Just practicing some bash shell scripting; looping constructs & conditional statements.
_testAbc ()
{
for abc in "$(which scp)";
do
if [[ -e "$abc" ]]; then
echo -e "true\n$abc";
fi;
done
}
# _testAbc #