-
Notifications
You must be signed in to change notification settings - Fork 13
/
05_network
64 lines (48 loc) · 1.16 KB
/
05_network
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Useful function for network information finding
function ipsort {
sort -t . -k 1,1n -k 2,2n -k 3,3n -k 4,4n
}
function strip_proto {
echo $1 | sed -E -e "s~(https?|ftp|ssh|rsync){0,1}://~~" -e "s~/.*~~"
}
function host {
local host=$(strip_proto $1)
shift
command host "${host}" "$@"
}
function dig {
local host=$(strip_proto $1)
shift
command dig "${host}" "$@"
}
function nslookup {
local host=$(strip_proto $1)
shift
command nslookup "${host}" "$@"
}
function ipwhois {
local host=$(strip_proto $1)
if [[ $host =~ [0-9]{1,3}\.[0-9]{1,3}\. ]]; then
local ip=$host
else
# Assuming this is a dns name
local ip=$(dig +short $host)
fi
if [[ -z "${ip}" ]]; then
return 1;
fi
echo "IP whois for ${ip}"
command whois "${ip}" "$@"
}
# Taken from: https://github.com/twe4ked/dotfiles/blob/master/shell/functions/ping.sh
# Modified to pull out strip_proto func and improve proto list
function ping {
local host=$(strip_proto $1)
shift
command ping "$host" "$@"
}
function whois {
local host=$(strip_proto $1)
shift
command whois "$host" "$@"
}