mirror of
https://github.com/trimstray/the-book-of-secret-knowledge.git
synced 2024-12-19 09:56:14 +00:00
added 'Shell functions'
- signed-off-by: trimstray <trimstray@gmail.com>
This commit is contained in:
parent
e5f721c0b0
commit
26a7ea7ea7
84
README.md
84
README.md
@ -88,6 +88,7 @@ Only main chapters:
|
|||||||
- **[Your daily knowledge and news](#your-daily-knowledge-and-news-toc)**
|
- **[Your daily knowledge and news](#your-daily-knowledge-and-news-toc)**
|
||||||
- **[Other Cheat Sheets](#other-cheat-sheets-toc)**
|
- **[Other Cheat Sheets](#other-cheat-sheets-toc)**
|
||||||
- **[One-liners](#one-liners-toc)**
|
- **[One-liners](#one-liners-toc)**
|
||||||
|
- **[Shell functions](#shell-functions-toc)**
|
||||||
|
|
||||||
## :trident: The Book of Secret Knowledge (Chapters)
|
## :trident: The Book of Secret Knowledge (Chapters)
|
||||||
|
|
||||||
@ -2900,3 +2901,86 @@ grep -v ^[[:space:]]*# filename
|
|||||||
```bash
|
```bash
|
||||||
egrep -v '#|^$' filename
|
egrep -v '#|^$' filename
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Shell functions [<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.
|
||||||
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user