-
Notifications
You must be signed in to change notification settings - Fork 1
/
iplocator.sh
executable file
·54 lines (41 loc) · 1.14 KB
/
iplocator.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
#!/bin/bash
#set -xe
#iplocater.sh
INPUT=$1
DIR=/tmp/test1.txt
function fetch(){
curl -s -H "User-Agent: keycdn-tools:https://veekrum.github.io" https://tools.keycdn.com/geo.json?host={$INPUT} | \
sed -e 's/[{}]/''/g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | \
grep 'isp\|country_name\|city\|ip\|latitude\|longitude\|region_name\|continent_name\|metro_code' | \
sed -e 's/"/''/g' | sed -e 's/:/= /g'> $DIR
cat $DIR
rm $DIR
}
function usage {
echo -e "Usage: IPLocator [OPTIONS]";
echo -e "\t-h | --help\tShow the help"
echo -e "\t-v | --version\tVersion Infomation"
echo -e "\t-u | --usage \t Usage "
}
function msg {
echo
echo -e "\t -iplocator [domain-name] [i.e www.example.com or example.com]"
echo -e "\t -iplocator [IP] [i.e 127.0.0.1]"
}
function check {
#if [[ -n "$1" ]]; then
if [ "$1" != "" ]; then
echo // $1 cannot be empty because it does not exist
else
fetch
fi
}
while true; do
case $1 in
-h|--help) usage; exit;;
-u|--usage) msg; exit;;
-v|--version) cat "$INSTALL_DIR.version"; exit;;
*) check; exit;;
esac
done
fetch