-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
115 lines (100 loc) · 4.22 KB
/
test.sh
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#! /usr/bin/bash
#function to run whois, will get the domain name from mainFun
#--------------------------------
runWhois() {
echo "-----------------------------------------------------------------------------"
echo "Please find the WhoIs details for" $1 "below"
echo "-----------------------------------------------------------------------------"
echo "-----------------------------------------------------------------------------"
echo "Registrar Details"
echo "-----------------------------------------------------------------------------"
whois $1 | grep 'Registrar WHOIS Server:' | tail -1
whois $1 | grep 'Registrar URL:' | tail -1
whois $1 | grep 'Updated Date:' | tail -1
whois $1 | grep 'Creation Date:' | tail -1
whois $1 | grep 'Registrar Registration Expiration Date:' | tail -1
whois $1 | grep 'Registrar:' | tail -1
whois $1 | grep 'Registrar Abuse Contact Email:' | tail -1
echo "-----------------------------------------------------------------------------"
echo "Registrant Details:"
echo "-----------------------------------------------------------------------------"
whois $1 | grep -m1 'Registrant Name:'
whois $1 | grep -m1 'Registrant Organization:'
whois $1 | grep -m1 'Registrant Country:'
whois $1 | grep -m1 'Registrant Email:'
echo "-----------------------------------------------------------------------------"
echo "Admin Details:"
echo "-----------------------------------------------------------------------------"
whois $1 | grep -m1 'Admin Name:'
whois $1 | grep -m1 'Admin Organization:'
whois $1 | grep -m1 'Admin Country:'
whois $1 | grep -m1 'Admin Email:'
echo "-----------------------------------------------------------------------------"
echo "Tech Details:"
echo "-----------------------------------------------------------------------------"
whois $1 | grep -m1 'Tech Name:'
whois $1 | grep -m1 'Tech Organization:'
whois $1 | grep -m1 'Tech Country:'
whois $1 | grep -m1 'Tech Email:'
echo "-----------------------------------------------------------------------------"
echo "Name Servers"
echo "-----------------------------------------------------------------------------"
whois $1 | grep 'Name Server:' | tail -4
echo "-----------------------------------------------------------------------------"
echo "Canonical Name"
echo "-----------------------------------------------------------------------------"
nslookup "www."$1 | grep 'canonical'
echo "-----------------------------------------------------------------------------"
echo "A Record" $1
echo "-----------------------------------------------------------------------------"
dig +noall +answer $1
}
#function to run Whois for Ip address
runWhoisIP(){
echo "-----------------------------------------------------------------------------"
echo "Please find the WhoIs details for" $1 "below"
echo "-----------------------------------------------------------------------------"
whois $1 | tail -n +11 | head -n -10
echo "-----------------------------------------------------------------------------"
echo "A Record" $1
echo "-----------------------------------------------------------------------------"
dig -x $1 | grep 'ANSWER SECTION' -A 1
}
#main function to determine the domain name and send it to runWhois function
#-----------------------------
mainFun() {
echo "Please enter the website for WhoIs"
read input
#to check if there are any spaces in the reading, if yes will call mainFun again
if [[ "$input" =~ \ |\' ]]
then
echo "There is a space please do it again without space."
mainFun
else
if [[ $input =~ ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$ ]] #checks if email
then
email=$(echo "$input" | egrep -o '@+[a-zA-Z0-9.-]+.[a-zA-Z0-9.-]')
dom=$(echo "$email" | cut -c 2-)
runWhois "$dom"
elif [[ $input == *"www."* ]] #checks if website
then
webs=$(echo "$input" | egrep -o 'www.+[a-zA-Z0-9.-]+.[a-zA-Z0-9.-]')
dom=$(echo "$webs" | cut -c 5-)
runWhois "$dom"
elif [[ $input =~ [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3} ]] #checks if IP
then
dom=$input
runWhoisIP "$dom"
elif [[ $input =~ ^[a-zA-Z0-9\.-]+\.[a-zA-Z]{2,4}$ ]] #checks if only domain
then
dom=$input
runWhois "$dom"
else
echo "You have entered a wrong domain, email, website or Ip address. Please retry."
mainFun
fi
fi
}
#--------------------------------
#mainFun ends
mainFun