Skip to content

Commit 1dbd99a

Browse files
authored
Merge pull request ruanyf#32 from Code-Blooded-Human/master
Added whereIP.sh, Get location of IP
2 parents 01927f7 + f65628c commit 1dbd99a

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ A collection of simple Bash scripts.
2828
1. [Encrypt.sh](scripts/encrypt.sh): encrypt a file/folder with password
2929
1. [Archive-and-encrypt.sh](scripts/archive-and-encrypt.sh): archive a path into a file and encrypt the file
3030
1. [weather.sh](scripts/weather.sh): check the weather in a specified location or using the geolocation of the ip address by default.
31-
31+
1. [WhereIP.sh](scripts/whereIP.sh): Get location of an IP address.
3232
## System Administration
3333

3434
1. [DirectorySize.sh](scripts/directorysize.sh): output a specified directory's size

scripts/whereIP.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
3+
#
4+
# Author: Abhishek Shingane ([email protected])
5+
# Date: 11 Sep 2020
6+
#
7+
8+
if ! [ -x "$(command -v jq)" ]; then
9+
echo 'Error: jq is not installed. Install via https://stedolan.github.io/jq/download/'
10+
exit 1
11+
fi
12+
13+
if [[ $# -ne 1 ]]; then
14+
echo 'Provide I.P as command line parameter. Usage: ' $0 ' 15.45.0.1 '
15+
exit 1
16+
fi
17+
link=$(echo "http://ip-api.com/json/"$1)
18+
data=$(curl $link -s) # -s for slient output
19+
20+
status=$(echo $data | jq '.status' -r)
21+
22+
if [[ $status == "success" ]]; then
23+
24+
city=$(echo $data | jq '.city' -r)
25+
regionName=$(echo $data | jq '.regionName' -r)
26+
country=$( echo $data | jq '.country' -r)
27+
echo $city, $regionName in $country.
28+
fi
29+
30+

0 commit comments

Comments
 (0)