2016-10-15 08:05:02 -05:00
|
|
|
### list of functions to source ###
|
|
|
|
|
|
|
|
randpw()
|
2016-10-15 08:29:29 -05:00
|
|
|
|
2016-10-15 08:05:02 -05:00
|
|
|
{
|
2016-10-15 08:29:29 -05:00
|
|
|
openssl rand -base64 12
|
2016-10-15 08:05:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
cipher_check()
|
2016-10-15 08:29:29 -05:00
|
|
|
|
2016-10-15 08:05:02 -05:00
|
|
|
{
|
2016-10-15 08:29:29 -05:00
|
|
|
nmap --script ssl-enum-ciphers "$1"
|
2016-10-15 08:05:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
check_gzip()
|
2016-10-15 08:29:29 -05:00
|
|
|
|
2016-10-15 08:05:02 -05:00
|
|
|
{
|
2016-10-15 08:29:29 -05:00
|
|
|
curl -I -H 'Accept-Encoding: gzip,deflate' "$1" 2> /dev/null | grep --color 'Content-Encoding' && 'echo gzip enabled' || echo 'gzip not enabled'
|
2016-10-15 08:05:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
ns()
|
2016-10-15 08:29:29 -05:00
|
|
|
|
2016-10-15 08:05:02 -05:00
|
|
|
{
|
2016-10-15 08:29:29 -05:00
|
|
|
dig +short "$1"
|
2016-10-15 08:05:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
mx()
|
2016-10-15 08:29:29 -05:00
|
|
|
|
|
|
|
{
|
|
|
|
dig +short MX "$1"
|
|
|
|
}
|
|
|
|
|
|
|
|
open_urls()
|
|
|
|
|
|
|
|
{
|
|
|
|
xargs -a "$1" firefox -new-tab "$line"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
check_open_resolver()
|
|
|
|
|
2016-10-15 08:05:02 -05:00
|
|
|
{
|
2016-10-15 08:29:29 -05:00
|
|
|
nmap -sU -p 53 -sV -P0 --script "dns-recursion" "$1"
|
2016-10-15 08:05:02 -05:00
|
|
|
}
|
2016-10-16 03:48:44 -05:00
|
|
|
|
|
|
|
fix_spaces()
|
|
|
|
|
|
|
|
{
|
|
|
|
for i in $1/*
|
|
|
|
do mv -v "$i" "$(echo $i | sed 's/ /_/g')"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
sqrt()
|
|
|
|
|
|
|
|
{
|
2016-10-17 13:55:48 -05:00
|
|
|
[ $# -ne 1 ] &&
|
|
|
|
{
|
2016-10-16 03:48:44 -05:00
|
|
|
echo 'Usage: sqrt number'
|
|
|
|
exit 1
|
2016-10-17 13:55:48 -05:00
|
|
|
} ||
|
2016-10-16 03:48:44 -05:00
|
|
|
echo -e "sqrt($1)\nquit\n" | bc -q -i | head -2 | tail -1
|
|
|
|
}
|
|
|
|
|
|
|
|
cx()
|
|
|
|
|
|
|
|
{
|
|
|
|
chmod +x $1
|
|
|
|
}
|
|
|
|
|
|
|
|
ssl()
|
|
|
|
|
2016-10-16 09:35:31 -05:00
|
|
|
{
|
2016-10-16 03:48:44 -05:00
|
|
|
openssl s_client -connect $1:443
|
|
|
|
}
|
|
|
|
|
|
|
|
mem_usage()
|
|
|
|
|
|
|
|
{
|
|
|
|
ps aux |grep -v USER|awk '{ cpu[$1]+=$3; rss[$1]+=$6; sum+=$6} END { for (user in cpu) printf("%-11s Memory: %9.1f MiB CPU%%: %5.1f\n", user, rss[user]/1024, cpu[user]); } END {printf("Total Memory: %15.1f MiB", sum/1024);}'|sort -n -k3;echo;free -m|egrep -v 'Mem|Swap'
|
|
|
|
}
|
|
|
|
|
2016-10-16 09:42:03 -05:00
|
|
|
|
|
|
|
# this will grab swap usage and each program using swap and total it.
|
2016-10-16 03:48:44 -05:00
|
|
|
swap_sum()
|
|
|
|
|
|
|
|
{
|
|
|
|
for dir in $(find /proc/ -maxdepth 1 -type d | egrep "^/proc/[0-9]") ; do pid=$(echo $dir | cut -d / -f 3);prog=$(ps -p $pid -o comm --no-headers|awk '{print $1}'); for swap in $(grep Swap $dir/smaps 2>/dev/null| awk '{print $2}');do let sum=$sum+$swap; done; echo "$prog $sum "|grep -vw 0;sum=0;done|awk '{ swap[$1]+=$2; sum+=$2} END { for (prog in swap) printf("%-15s Swap: %10.1f MiB\n", prog, swap[prog]/1024); } END {printf("Total Swap: %20.1f MiB", sum/1024);}'|sort -n -k3
|
|
|
|
}
|
2016-10-16 07:41:03 -05:00
|
|
|
|
|
|
|
# Extra many types of compressed packages
|
|
|
|
# Credit: http://nparikh.org/notes/zshrc.txt
|
|
|
|
extract()
|
2016-10-17 03:18:20 -05:00
|
|
|
|
2016-10-16 07:41:03 -05:00
|
|
|
{
|
|
|
|
if [ -f "$1" ]; then
|
|
|
|
case "$1" in
|
|
|
|
*.tar.bz2) tar -jxvf "$1" ;;
|
|
|
|
*.tar.gz) tar -zxvf "$1" ;;
|
|
|
|
*.bz2) bunzip2 "$1" ;;
|
|
|
|
*.dmg) hdiutil mount "$1" ;;
|
|
|
|
*.gz) gunzip "$1" ;;
|
|
|
|
*.tar) tar -xvf "$1" ;;
|
|
|
|
*.tbz2) tar -jxvf "$1" ;;
|
|
|
|
*.tgz) tar -zxvf "$1" ;;
|
|
|
|
*.zip) unzip "$1" ;;
|
|
|
|
*.ZIP) unzip "$1" ;;
|
|
|
|
*.pax) cat "$1" | pax -r ;;
|
|
|
|
*.pax.Z) uncompress "$1" --stdout | pax -r ;;
|
|
|
|
*.Z) uncompress "$1" ;;
|
|
|
|
*) echo "'$1' cannot be extracted/mounted via extract()" ;;
|
|
|
|
esac
|
|
|
|
else
|
|
|
|
echo "'$1' is not a valid file to extract"
|
|
|
|
fi
|
|
|
|
}
|
2016-10-17 03:18:20 -05:00
|
|
|
|
|
|
|
#global_python()
|
|
|
|
#{
|
|
|
|
# export PATH=$PATH
|
|
|
|
#
|
|
|
|
#}
|
|
|
|
|
|
|
|
user_python()
|
|
|
|
|
|
|
|
{
|
|
|
|
[[ -d "$HOME/install/python" ]] && export PATH="$PATH:/install/python/bin"
|
|
|
|
}
|
|
|
|
|
|
|
|
add_underscore()
|
|
|
|
|
|
|
|
{
|
|
|
|
sed -e s'/ /_/g' #single line to rename from pipe
|
|
|
|
}
|
|
|
|
|
|
|
|
rot13()
|
|
|
|
|
|
|
|
{
|
|
|
|
if [ -r $1 ]; then cat $1 | tr '[N-ZA-Mn-za-m5-90-4]' '[A-Za-z0-9]'; else echo $* | tr '[N-ZA-Mn-za-m5-90-4]' '[A-Za-z0-9]'; fi
|
|
|
|
}
|
|
|
|
|
|
|
|
histupdate()
|
|
|
|
|
|
|
|
{
|
|
|
|
history -a; history -n
|
|
|
|
}
|
|
|
|
|
|
|
|
mostusedcmds()
|
|
|
|
|
|
|
|
{
|
|
|
|
history | awk '{ print $2}' | sort | uniq -c | sort -rn | head
|
|
|
|
}
|
|
|
|
|
|
|
|
on()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
user="$1"
|
|
|
|
|
|
|
|
if who | grep "^$user " > /dev/null; then
|
|
|
|
echo "$user is logged in"
|
|
|
|
fi
|
|
|
|
|
|
|
|
}
|
2017-03-28 12:58:05 -05:00
|
|
|
|
|
|
|
multiplication_table()
|
|
|
|
|
|
|
|
{
|
|
|
|
for y in {1..10}; do
|
|
|
|
for x in {1..10}; do echo -n "| $x*$y=$((y*x)) ";
|
|
|
|
done; echo; done| column -t
|
2017-03-28 13:00:13 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-01-30 22:30:01 -06:00
|
|
|
cve_lookup()
|
|
|
|
|
|
|
|
{
|
|
|
|
[[ -z "$1" ]] && echo "Usage: $0 CVE-YYYY-NNNN"
|
|
|
|
|
|
|
|
curl -s http://www.cvedetails.com/cve/$1/ | grep 'meta name="description" content="' | awk -F\" '{print $4}'
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-01-31 00:52:06 -06:00
|
|
|
|
|
|
|
swap_used()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
SUM=0
|
|
|
|
OVERALL=0
|
|
|
|
for DIR in `find /proc/ -maxdepth 1 -type d -regex "^/proc/[0-9]+"`
|
|
|
|
do
|
|
|
|
PID=`echo $DIR | cut -d / -f 3`
|
|
|
|
PROGNAME=`ps -p $PID -o comm --no-headers`
|
|
|
|
for SWAP in `grep Swap $DIR/smaps 2>/dev/null | awk '{ print $2 }'`
|
|
|
|
do
|
|
|
|
let SUM=$SUM+$SWAP
|
|
|
|
done
|
|
|
|
if (( $SUM > 0 )); then
|
|
|
|
echo "PID=$PID swapped $SUM KB ($PROGNAME)"
|
|
|
|
fi
|
|
|
|
let OVERALL=$OVERALL+$SUM
|
|
|
|
SUM=0
|
|
|
|
done
|
|
|
|
echo "Overall swap used: $OVERALL KB"
|
2017-03-28 12:58:05 -05:00
|
|
|
}
|
2017-05-11 11:53:11 -05:00
|
|
|
|
|
|
|
hddtemps()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
for drive in $(ls /dev/sd[a-z]); do sudo hddtemp $drive; done
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
suptime()
|
|
|
|
|
|
|
|
{
|
|
|
|
local addr=${1:?Specify the remote IPv4 address}
|
|
|
|
local port=${2:?Specify the remote port number}
|
|
|
|
# convert the provided address to hex format
|
|
|
|
local hex_addr=$(python -c "import socket, struct; print(hex(struct.unpack('<L', socket.inet_aton('$addr'))[0])[2:10].upper().zfill(8))")
|
|
|
|
local hex_port=$(python -c "print(hex($port)[2:].upper().zfill(4))")
|
|
|
|
# get the PID of the owner process
|
|
|
|
local pid=$(netstat -ntp 2>/dev/null | awk '$6 == "ESTABLISHED" && $5 == "'$addr:$port'"{sub("/.*", "", $7); print $7}')
|
|
|
|
[ -z "$pid" ] && { echo 'Address does not match' 2>&1; return 1; }
|
|
|
|
# get the inode of the socket
|
|
|
|
local inode=$(awk '$4 == "01" && $3 == "'$hex_addr:$hex_port'" {print $10}' /proc/net/tcp)
|
|
|
|
[ -z "$inode" ] && { echo 'Cannot lookup the socket' 2>&1; return 1; }
|
|
|
|
# query the inode status change time
|
|
|
|
local timestamp=$(find /proc/$pid/fd -lname "socket:\[$inode\]" -printf %T@)
|
|
|
|
[ -z "$timestamp" ] && { echo 'Cannot fetch the timestamp' 2>&1; return 1; }
|
|
|
|
# compute the time difference
|
|
|
|
LANG=C printf '%s (%.2fs ago)\n' "$(date -d @$timestamp)" $(bc <<<"$(date +%s.%N) - $timestamp")
|
|
|
|
}
|
2017-06-21 11:12:11 -05:00
|
|
|
|
2017-09-06 22:45:34 -05:00
|
|
|
tcp()
|
2017-06-21 11:12:11 -05:00
|
|
|
{
|
2017-09-06 22:45:34 -05:00
|
|
|
netstat -nap | egrep "^tcp6{0,1} " 2> /dev/null | tr "\t" " " \
|
2017-06-21 11:12:11 -05:00
|
|
|
| sed 's/ */ /g;s/ $//g' \
|
|
|
|
| egrep '^tcp6{0,1} [0-9]+ [0-9]+ [0.:]+:[0-9]+ [0.:]+:\* LISTEN ' \
|
|
|
|
| sed 's/^tcp[6 ]*[0-9]* [0-9]* [0.:]*:\([0-9]*\) [0.:]*:\* LISTEN \(.*\)/"\2","tcp",\1/' \
|
2017-09-06 22:45:34 -05:00
|
|
|
| sed 's#^"[0-9]*/#"#' | sort -t"," -k3n | uniq
|
2017-06-21 11:12:11 -05:00
|
|
|
}
|
|
|
|
|
2017-09-06 22:45:34 -05:00
|
|
|
udp()
|
2017-06-21 11:12:11 -05:00
|
|
|
{
|
2017-09-06 22:45:34 -05:00
|
|
|
netstat -nap | egrep "^udp6{0,1} " 2> /dev/null | tr "\t" " " \
|
2017-06-21 11:12:11 -05:00
|
|
|
| sed 's/ */ /g;s/ $//g' \
|
|
|
|
| egrep '^udp6{0,1} [0-9]+ [0-9]+ [0.:]+:[0-9]+ [0.:]+:\* ' \
|
|
|
|
| sed 's/^udp[6 ]*[0-9]* [0-9]* [0.:]*:\([0-9]*\) [0.:]*:\* \(.*\)/"\2","udp",\1/' \
|
2017-09-06 22:45:34 -05:00
|
|
|
| sed 's#^"[0-9]*/#"#' | sort -t"," -k3n | uniq
|
2017-06-21 11:12:11 -05:00
|
|
|
}
|