Skip to content

Instantly share code, notes, and snippets.

@5kr1p7
Last active October 11, 2022 12:09
Show Gist options
  • Save 5kr1p7/a364f3991d5abc5f0347d1eece44b203 to your computer and use it in GitHub Desktop.
Save 5kr1p7/a364f3991d5abc5f0347d1eece44b203 to your computer and use it in GitHub Desktop.

Notes (Bash, Shell)

Network

Get own IP address

curl -ks "https://ipv4.myip.info/"
curl -ks "https://ifconfig.me/"

Get IPv4 address in PTR-record format

echo '95.213.11.181' | awk -v OFS="." -F"." '{ print $4,$3,$2,$1,"in-addr.arpa" }'

Get BGP AS number by hostname

whois $(dig -t a "vk.com" @62.76.76.62 | grep '^[^;].*IN.*A.*' | head -1 | grep -o '\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}') | \
grep '^origin:' | sed -e 's/[ ]//g' | cut -d':' -f2

Get sorted prefix list by AS number

curl -s "https://stat.ripe.net/data/announced-prefixes/data.json?preferred_version=1.1&resource=AS12389" | \
jq '.data.prefixes[].prefix' | \
tr -d '"' | sort -n -t . -k1,1 -k2,2 -k3,3 -k4,4 | uniq

Get list of IPs by prefix

nmap -sL -n 95.142.206.0/24 | \
grep "Nmap scan report for" | \
awk '{ print $NF}' | tail -n +2 | head -n -1

Get name of AS number

curl -s https://bgpstuff.net/asname/29648

Get DNS hostnames for IP list

nmap -sL 95.142.206.0/24 | \
grep "^Nmap scan" | sed -e 's/^Nmap scan report for //g' | \
sed -e 's/\(.*\)(\(.*\))/\2  \1/g'

Compress and copy folder via SSH

ssh ${HOST} "tar cvzf - ${SOURCE}" > ${DESTINATION}.tar.gz

Docker

Get run command of started container:

docker run --rm -v /var/run/docker.sock:/var/run/docker.sock:ro assaflavie/runlike <CONTAINER_NAME>

Misc

USD exchange rate (RUB)

curl -s "https://www.cbr-xml-daily.ru/daily_json.js" | \
jq '.Valute.USD.Value'

BTC exchange rate (USD)

curl -s "https://api.coinmarketcap.com/v1/ticker/" | \
jq '.[] | select(.id == "bitcoin").price_usd' | tr -d '"'

Parsing web pages

wget -q -O - https://mikrotik.com/download | xmllint --debug --html --xpath '(//table[@class = "table downloadTable"]/thead//th[2])[last()]/text()' - 2>/dev/null
wget -q -O - https://mikrotik.com/download | xmllint --debug --html --xpath '(//table[contains(@class, "downloadTable")]/thead//th[2])[last()]/text()' - 2>/dev/null

Transliterate russian letters

#!/bin/sh

echo $1 | \
sed 'y/АБВГДЖЗИЙКЛМНОПРСТУФХЫЭЕ/ABVGDJZIJKLMNOPRSTUFHYEE/' | \
sed 's/[ЬЪ]//g; s/Ё/Yo/g; s/Ц/Ts/g; s/Ч/Ch/g; s/Ш/Sh/g; s/Щ/Sch/g; s/Ю/yu/g; s/Я/Ya/' | \
sed 'y/абвгджзийклмнопрстуфхыэе/abvgdjzijklmnoprstufhyee/' | \
sed 's/[ьъ]//g; s/ё/yo/g; s/ц/ts/g; s/ч/ch/g; s/ш/sh/g; s/щ/sch/g; s/ю/yu/g; s/я/ya/'

Generate UUID

cat /proc/sys/kernel/random/uuid

Find large files and its size

find / -type f -size +100M -exec ls -lh {} \; | awk '{ print $9 "|| Size : " $5 }'

Get Request per second from nginx

cat /var/log/nginx/access.log | awk '{print $4}' | uniq -c | sort -rn | head

Upgrade all

apt-get update && apt-get upgrade -y && apt dist-upgrade && apt-get clean && apt-get autoremove \
&& helm repo update \
&& sudo -i -u ${USER} /home/${USER}/.linuxbrew/bin/brew update && sudo -i -u ${USER} /home/${USER}/.linuxbrew/bin/brew upgrade \
&& snap refresh \
&& upgrade_oh_my_bash

Git

Get latest changes by date

git status -s | while read mode file; do echo $mode $file $(stat -f "%Sm %N" -t "%Y-%m-%d %H:%M:%S" $file); done | grep "$(date +%Y-%m)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment