Pārlūkot izejas kodu

added 'Shell functions'

- signed-off-by: trimstray <trimstray@gmail.com>
pull/78/head
trimstray pirms 5 gadiem
vecāks
revīzija
26a7ea7ea7
1 mainītis faili ar 84 papildinājumiem un 0 dzēšanām
  1. +84
    -0
      README.md

+ 84
- 0
README.md Parādīt failu

@@ -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: &nbsp;The Book of Secret Knowledge (Chapters)

@@ -2900,3 +2901,86 @@ grep -v ^[[:space:]]*# filename
```bash
egrep -v '#|^$' filename
```

#### Shell functions &nbsp;[<sup>[TOC]</sup>](#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.
```

Notiek ielāde…
Atcelt
Saglabāt