diff --git a/README.md b/README.md index e7a07f0..cbd9941 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,7 @@ Only main chapters: - **[Your daily knowledge and news](#your-daily-knowledge-and-news-toc)** - **[Other Cheat Sheets](#other-cheat-sheets-toc)** - **[One-liners](#one-liners-toc)** +- **[Shell functions](#shell-functions-toc)** ## :trident:  The Book of Secret Knowledge (Chapters) @@ -2900,3 +2901,86 @@ grep -v ^[[:space:]]*# filename ```bash egrep -v '#|^$' filename ``` + +#### Shell functions  [[TOC]](#anger-table-of-contents) + +###### Domain resolve + +```bash +# Dependencies: +# - curl +# - jq + +function DomainResolve() { + + local _host="$1" + + local _curl_base="curl --request GET" + local _timeout="15" + + _host_ip=$($_curl_base -ks -m "$_timeout" "https://dns.google.com/resolve?name=${_host}&type=A" | \ + jq '.Answer[0].data' | tr -d "\"" 2>/dev/null) + + if [[ -z "$_host_ip" ]] || [[ "$_host_ip" == "null" ]] ; then + + echo -en "Unsuccessful domain name resolution.\\n" + + else + + echo -en "$_host > $_host_ip\\n" + + fi + +} +``` + +Example: + +```bash +shell> DomainResolve nmap.org +nmap.org > 45.33.49.119 + +shell> DomainResolve nmap.orgs +Unsuccessful domain name resolution. +``` + +###### Get ASN + +```bash +# Dependencies: +# - curl +# - python + +function GetASN() { + + local _ip="$1" + + local _curl_base="curl --request GET" + local _timeout="15" + + _asn=$($_curl_base -ks -m "$_timeout" "http://ip-api.com/json/${_ip}" | python -c 'import sys, json; print json.load(sys.stdin)["as"]' 2>/dev/null) + + _state=$(echo $?) + + if [[ -z "$_ip" ]] || [[ "$_ip" == "null" ]] || [[ "$_state" -ne 0 ]]; then + + echo -en "Unsuccessful ASN gathering.\\n" + + else + + echo -en "$_ip > $_asn\\n" + + fi + +} +``` + +Example: + +```bash +shell> GetASN 1.1.1.1 +1.1.1.1 > AS13335 Cloudflare, Inc. + +shell> GetASN 0.0.0.0 +Unsuccessful ASN gathering. +```