diff --git a/.bashrc b/.bashrc index 9d9b6b562380e7f12a64a8b7e819409ec32c683d..284a3116cc978bc0593c085928718311b1c8803c 100644 --- a/.bashrc +++ b/.bashrc @@ -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 diff --git a/Documents/bin/ipinfo b/Documents/bin/ipinfo new file mode 100755 index 0000000000000000000000000000000000000000..b7a96f73ea3e12f9b2adfeaa9722d479f9b12953 --- /dev/null +++ b/Documents/bin/ipinfo @@ -0,0 +1,36 @@ +#!/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