-
Notifications
You must be signed in to change notification settings - Fork 0
/
getIpWhoisInfo.sh
executable file
·74 lines (61 loc) · 1.67 KB
/
getIpWhoisInfo.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
#!/bin/bash
check_tool(){
if ! [ -x "$(command -v $1)" ]; then
echo -e "\e[31m[-] curl no instalado\e[0m"
exit 1
fi
}
check_tool "curl"
ip=""
help(){
echo "Usage: $0 -i IP"
echo
echo "Desccripción:"
echo "- Se hace uso de ipinfo --> Limitado"
echo "- Se hace uso de lacnic"
echo
echo "Opciones:"
echo " -h Show this message"
echo " -i IPv4 o IPv6. Para LACNIC solo IPv4"
}
while getopts "i:h" opt; do
case $opt in
(i)
ip="$OPTARG"
;;
(h)
help
exit 0
;;
(\?)
echo "Usage: $0 -i IPv4/IPv6"
exit 1
;;
esac
done
if [ -z "$ip" ]; then
help
exit 1
fi
if [ -n "$ip" ]; then
response_ipinfo=$(curl -s https://ipinfo.io/widget/demo/$ip)
response_lacnic=$(curl -s https://rdap.lacnic.net/rdap/whois/$ip)
if [[ "$response_ipinfo" == *"Too Many Requests"* ]]; then
echo -e "\e[31m[-] Usando el motor ipinfo.io\e[0m"
echo "$response_ipinfo"
else
echo -e "\e[32m[+] Usando el motor ipinfo.io\e[0m"
echo "$response_ipinfo" | jq
fi
if [[ "$response_lacnic" == *"% No match for"* || "$response_lacnic" == *"Timeout"* ]]; then
echo -e "\e[31m[-] Usando el motor lacnic.com\e[0m"
if [[ "$response_lacnic" == *"Timeout"* ]]; then
echo $response_lacnic
else
echo "No match for $ip"
fi
else
echo -e "\e[32m[+] Usando el motor lacnic.com\e[0m"
echo "$response_lacnic" | sed '/^%/d' | awk 'NF' | awk '{ gsub(/^[ \t]+/, "", $0); gsub(/[ \t]+$/, "", $0); print }'
fi
fi