From c00e40be39fe9ef779bbf51b65f88209b80f5a8d Mon Sep 17 00:00:00 2001 From: fabio Date: Mon, 8 Jun 2020 20:30:12 +0200 Subject: [PATCH] added more utilities --- README.md | 115 ++++++++++++++++++++++++++++++++++++++++++++++-- blink_port | 10 +++++ cert_expire | 3 ++ expose | 6 +++ gen_passwd | 6 +++ git_change_date | 2 + git_commit | 2 + installer | 10 +++++ ip_location | 2 + ip_public | 2 + mac_random | 2 + pdf_compress | 3 ++ server_specs | 24 ++++++++++ stealth | 2 + timestamp | 3 ++ 15 files changed, 189 insertions(+), 3 deletions(-) create mode 100755 blink_port create mode 100755 cert_expire create mode 100755 expose create mode 100755 gen_passwd create mode 100755 git_change_date create mode 100755 git_commit create mode 100644 installer create mode 100755 ip_location create mode 100755 ip_public create mode 100755 mac_random create mode 100755 pdf_compress create mode 100755 server_specs create mode 100755 stealth create mode 100755 timestamp diff --git a/README.md b/README.md index 523d053..e50145b 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,42 @@ # Utils +## Requirements + + - Python3 + - Ghostscript + +## Install + +One liner: + +```shell +wget -O- https://raw.githubusercontent.com/fabiocicerchia/utils/master/installer | sudo sh +``` + ## Tools -### Benchmark +### `benchmark` - Benchmark URL ```shell $ benchmark URL 0.12345 sec ``` -### Check Accessibility +### `blink_port` - Blink NIC led + +```shell +$ blink_port [NIC=eth0] [TIME=5] +``` + +### `cert_expire` - SSL/TLS Certificate Expiration + +```shell +$ cert_expire DOMAIN +notBefore=May 20 11:55:41 2020 GMT +notAfter=Aug 12 11:55:41 2020 GMT +``` + +### `check_accessibility` - Check Accessibility ```shell $ check_accessibility URL @@ -26,7 +53,7 @@ Validate Accessibility (WCAG 2.0 - Level AAA): OK|FAIL ``` -### Check Validation +### `check_validation` - Check Validation ```shell $ check_validation URL @@ -51,6 +78,88 @@ Validate Links: OK|FAIL ``` +### `expose` - Expose Folder to HTTP port + +```shell +$ expose [PORT=8080] +Serving HTTP on 0.0.0.0 port 8080 (http://0.0.0.0:8080/) ... +``` + +### `gen_passwd` - Generate Password + +```shell +$ gen_passwd [LEN=16] +******* +``` + +### `git_change_date` - Git Change Date + +```shell +$ git_change_date "Mon 08 Jun 2020 20:19:19 CET" +``` + +### `git_commit` - Git Commit Random Message + +```shell +$ git_commit +``` + +### `ip_location` - IP Location + +```shell +$ ip_location 123.123.123.123 +Italy +IT +Rome +``` + +### `ip_public` - Public IP Address + +```shell +$ ip_public +123.123.123.123 +``` + +### `mac_random` - Random MAC Address + +```shell +$ mac_random +86:ed:59:63:20:58 +``` + +### `pdf_compress` - Compress PDF's size + +```shell +$ pdf_compress FILE.PDF +``` + +### `server_specs` - Server Specs + +```shell +$ server_specs +CPU: 4 +RAM: 16384 MB +Swap: 2048 MB +Disk: 10Gi +Avg load: 1.53 1.87 1.91 +IP Private: 192.168.0.2 +IP Public: 123.123.123.123 +Location: Italy +``` + +### `stealth` - Disable Command History + +```shell +$ stealth +``` + +### `timestamp` - Convert Timestamp + +```shell +$ timestamp 1234567890 +Fri Feb 13 15:26:30 EST 2009 +``` + ## Notes - Freeze the requirements: `pip3 freeze > requirements.txt` diff --git a/blink_port b/blink_port new file mode 100755 index 0000000..1d7bda2 --- /dev/null +++ b/blink_port @@ -0,0 +1,10 @@ +#!/bin/sh +NIC=eth0 +if [ "$1" != "" ]; then + NIC=$1 +fi +TIME=5 +if [ "$2" != "" ]; then + TIME=$2 +fi +ethtool -p $NIC $TIME diff --git a/cert_expire b/cert_expire new file mode 100755 index 0000000..d9d4236 --- /dev/null +++ b/cert_expire @@ -0,0 +1,3 @@ +#!/bin/sh +DOMAIN=$1 +echo | openssl s_client -connect $DOMAIN:443 2>/dev/null | openssl x509 -dates -noout diff --git a/expose b/expose new file mode 100755 index 0000000..504a459 --- /dev/null +++ b/expose @@ -0,0 +1,6 @@ +#!/bin/sh +PORT=8000 +if [ "$1" != "" ]; then + PORT=$1 +fi +python3 -m http.server $PORT diff --git a/gen_passwd b/gen_passwd new file mode 100755 index 0000000..d4c7266 --- /dev/null +++ b/gen_passwd @@ -0,0 +1,6 @@ +#!/bin/sh +LEN=16 +if [ "$1" != "" ]; then + LEN=$1 +fi +head -n 1 /dev/urandom | base64 | grep -o '[[:alnum:]]' | head -n $LEN | tr -d '\n' diff --git a/git_change_date b/git_change_date new file mode 100755 index 0000000..fe0447f --- /dev/null +++ b/git_change_date @@ -0,0 +1,2 @@ +#!/bin/sh +GIT_COMMITTER_DATE="$1" git commit --amend --no-edit --date "$1" diff --git a/git_commit b/git_commit new file mode 100755 index 0000000..00978c5 --- /dev/null +++ b/git_commit @@ -0,0 +1,2 @@ +#!/bin/sh +git commit -m "$(curl -s http://whatthecommit.com/index.txt)" diff --git a/installer b/installer new file mode 100644 index 0000000..e2684cf --- /dev/null +++ b/installer @@ -0,0 +1,10 @@ +#!/bin/sh + +mkdir /tmp/utils-installer +cd /tmp/utils-installer +wget https://github.com/fabiocicerchia/utils/archive/master.zip +unzip master.zip && rm master.zip +cd utils-master/ +rm installer *.* +cd /tmp/utils-installer/utils-master /opt/utils-master +echo "PATH=\$PATH:/opt/utils-master" | tee -a /etc/profile diff --git a/ip_location b/ip_location new file mode 100755 index 0000000..3246398 --- /dev/null +++ b/ip_location @@ -0,0 +1,2 @@ +#!/bin/sh +curl "http://ip-api.com/line/$1?fields=country,countryCode,city" diff --git a/ip_public b/ip_public new file mode 100755 index 0000000..2fd492d --- /dev/null +++ b/ip_public @@ -0,0 +1,2 @@ +#!/bin/sh +curl ifconfig.me diff --git a/mac_random b/mac_random new file mode 100755 index 0000000..6457e4d --- /dev/null +++ b/mac_random @@ -0,0 +1,2 @@ +#!/bin/bash +openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//' diff --git a/pdf_compress b/pdf_compress new file mode 100755 index 0000000..f66fa0a --- /dev/null +++ b/pdf_compress @@ -0,0 +1,3 @@ +#!/bin/sh +FILE=$1 +pdf2ps $FILE $FILE.ps && ps2pdf $FILE.ps $FILE && rm $FILE.ps diff --git a/server_specs b/server_specs new file mode 100755 index 0000000..e53e8af --- /dev/null +++ b/server_specs @@ -0,0 +1,24 @@ +#!/bin/sh +IS_NIX=$(which free) +echo "Arch: $(arch)" +if [ $IS_NIX ]; then + echo "CPU: $(nproc 2> /dev/null)" + echo "RAM: $(free -m 2> /dev/null | grep Mem | awk '{print $2}') MB" + echo "Swap: $(free -m 2> /dev/null | grep Swap | awk '{print $2}') MB" +else + echo "CPU: $(sysctl -n hw.physicalcpu)" + echo "RAM: $(echo $(($(sysctl -n hw.memsize) / 1024 / 1024))) MB" + echo "Swap: $(sysctl vm.swapusage | awk '{print $4}' | sed 's/\..*//') MB" +fi + +echo "Disk: $(df -h / | tail -n1 | awk '{print $3}')" +echo "Avg load: $(uptime | sed 's/.*: //')" +if [ $IS_NIX ]; then + echo "IP Private: $(ip addr show eth0 | grep "inet\b" | head -n1 | awk '{print $2}' | cut -d/ -f1)" +else + echo "IP Private: $(ifconfig en0 | grep "inet\b" | head -n1 | awk '{print $2}' | cut -d/ -f1)" +fi + +IP=$(curl -s ifconfig.me) +echo "IP Public: $IP" +echo "Location: $(curl -s http://ip-api.com/line/$IP?fields=country)" diff --git a/stealth b/stealth new file mode 100755 index 0000000..5a960ec --- /dev/null +++ b/stealth @@ -0,0 +1,2 @@ +#!/bin/sh +unset HISTFILE diff --git a/timestamp b/timestamp new file mode 100755 index 0000000..409c31b --- /dev/null +++ b/timestamp @@ -0,0 +1,3 @@ +#!/bin/sh +TIME=$1 +date -d@$TIME 2> /dev/null || date -r $TIME