Skip to content
Snippets Groups Projects
Commit 5aea62e8 authored by nimrod's avatar nimrod
Browse files

ipinfo script.

Get IP info from ipinfo.io.
parent c3547642
No related branches found
No related tags found
No related merge requests found
......@@ -231,7 +231,7 @@ gen_csr () {
jt () {
if command -v pygmentize > /dev/null
then
python3 -m json.tool "$@" | pygmentize -l javascript
python3 -m json.tool "$@" | pygmentize -l json
else
python3 -m json.tool "$@"
fi
......
#!/bin/sh
set -eu
is_ip () {
echo "$1" | grep --extended-regexp --quiet '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
}
usage () {
echo "USAGE: $(basename "$0") [-h] [hostname or IP address]" >&2
echo "If no address is passed, the internet IP address is used instead." >&2
}
if [ "$#" -eq 0 ]
then
address="$(curl --silent --fail --show-error https://myip.shore.co.il/)"
elif [ "$#" -gt 1 ]
then
usage
exit 1
elif [ "$1" = "-h" ]
then
usage
elif is_ip "$1"
then
address="$1"
else
address="$(dig +short "$1")"
fi
if command -v pygmentize > /dev/null
then
curl --silent --fail --show-error --header "Accept: application/json" "https://ipinfo.io/${address}" | pygmentize -l json
else
curl --fail --show-error --header "Accept: application/json" "https://ipinfo.io/${address}"
fi
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment