├── .gitignore ├── README.md ├── bin ├── domainsi ├── hosti ├── ipi ├── ipr └── iptools-install └── lib ├── colors.sh └── functions.sh /.gitignore: -------------------------------------------------------------------------------- 1 | config.json 2 | log.txt 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ipi 2 | I wrote this utility to help me more efficiently utilize the ipinfo.io API - especially the premium aspects. 3 | 4 | # Installation 5 | 6 | Sign in with Google or Github to obtain a free API key with 50k requests! 7 | https://ipinfo.io/account 8 | ``` 9 | wget -O /tmp/install https://raw.githubusercontent.com/pry0cc/ipi/master/bin/iptools-install && chmod +x /tmp/install 10 | /tmp/install 11 | ``` 12 | 13 | # Example 14 | ![](https://i.imgur.com/6QLIlCl.png) 15 | 16 | # Basic Usage 17 | 18 | Look up a single IP 19 | ``` 20 | ipi 8.8.8.8 21 | ``` 22 | 23 | Parse an item from the results 24 | ``` 25 | ipi 8.8.8.8 .city 26 | ``` 27 | 28 | Make a CSV of a single IP 29 | ``` 30 | ipi 104.238.184.224 '[.city, .region, .hostname] | @csv' 31 | ``` 32 | 33 | Or you can read from stdin 34 | 35 | ``` 36 | cat ips.txt | ipi '.asn.asn' 37 | ``` 38 | 39 | You can do the exact same with ipr too, which is for ranges: 40 | ``` 41 | ipr AS7922 42 | 43 | # Get all IP ranges for a given ASN 44 | ipr AS7922 '.prefixes[].netblock' 45 | ``` 46 | -------------------------------------------------------------------------------- /bin/domainsi: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DIR="$HOME/.ipi" 4 | 5 | source "$DIR/lib/colors.sh" 6 | source "$DIR/lib/functions.sh" 7 | 8 | if [ -t 0 ] 9 | then 10 | domain="$1" 11 | flags="$2" 12 | 13 | if [[ "$domain" == "" ]] 14 | then 15 | echo_error "No domain specified..." 16 | exit 17 | fi 18 | 19 | log "Queried for $domain" 20 | 21 | if [[ "$flags" != "" ]] 22 | then 23 | domains "$domain"| jq -r "$flags" 24 | else 25 | domains "$domain"| jq -C "$flags" 26 | fi 27 | else 28 | while read -r line 29 | do 30 | domain=$(echo $line | cut -d " " -f 2) 31 | flags="$1" 32 | 33 | if [[ "$domain" == "" ]] 34 | then 35 | echo_error "No domain specified..." 36 | exit 37 | fi 38 | 39 | log "Queried for $domain" 40 | 41 | if [[ "$flags" != "" ]] 42 | then 43 | domains "$domain"| jq -r "$flags" 44 | else 45 | domains "$domain"| jq -C "$flags" 46 | fi 47 | done 48 | fi 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /bin/hosti: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DIR="$HOME/.ipi" 4 | 5 | source "$DIR/lib/colors.sh" 6 | source "$DIR/lib/functions.sh" 7 | 8 | if [ -t 0 ] 9 | then 10 | host="$1" 11 | flags="$2" 12 | 13 | if [[ "$host" == "" ]] 14 | then 15 | echo_error "No Host specified..." 16 | exit 17 | fi 18 | 19 | log "Queried for $host" 20 | 21 | if [[ "$flags" != "" ]] 22 | then 23 | hostinfo "$host"| jq -r "$flags" 24 | else 25 | hostinfo "$host"| jq -C "$flags" 26 | fi 27 | else 28 | while read -r line 29 | do 30 | host=$(echo $line | cut -d " " -f 2) 31 | flags="$1" 32 | 33 | if [[ "$host" == "" ]] 34 | then 35 | echo_error "No Host specified..." 36 | exit 37 | fi 38 | 39 | log "Queried for $host" 40 | 41 | if [[ "$flags" != "" ]] 42 | then 43 | hostinfo "$host"| jq -r "$flags" 44 | else 45 | hostinfo "$host"| jq -C "$flags" 46 | fi 47 | done 48 | fi 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /bin/ipi: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DIR="$HOME/.ipi" 4 | 5 | source "$DIR/lib/colors.sh" 6 | source "$DIR/lib/functions.sh" 7 | 8 | if [ -t 0 ]; then 9 | 10 | ip="$1" 11 | flags="$2" 12 | 13 | 14 | if [[ "$ip" == "" ]] 15 | then 16 | echo_error "No IP specified..." 17 | exit 18 | fi 19 | 20 | log "Queried for $ip" 21 | 22 | if [[ "$flags" != "" ]] 23 | then 24 | info "$ip"| jq -r "$flags" 25 | else 26 | info "$ip"| jq -C "$flags" 27 | fi 28 | else 29 | while read -r line ; do 30 | ip=$(echo $line | cut -d " " -f 2) 31 | flags="$1" 32 | 33 | 34 | if [[ "$ip" == "" ]] 35 | then 36 | echo_error "No IP specified..." 37 | exit 38 | fi 39 | 40 | log "Queried for $ip" 41 | 42 | if [[ "$flags" != "" ]] 43 | then 44 | info "$ip"| jq -r "$flags" 45 | else 46 | info "$ip"| jq -C "$flags" 47 | fi 48 | done 49 | fi 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /bin/ipr: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DIR="$HOME/.ipi" 4 | 5 | source "$DIR/lib/colors.sh" 6 | source "$DIR/lib/functions.sh" 7 | 8 | 9 | if [ -t 0 ]; then 10 | asn="$1" 11 | flags="$2" 12 | 13 | if [[ "$asn" == "" ]] 14 | then 15 | echo_error "No ASN specified..." 16 | exit 17 | fi 18 | 19 | log "Queried for $asn" 20 | 21 | if [[ "$flags" != "" ]] 22 | then 23 | asn "$asn"| jq -r "$flags" 24 | else 25 | asn "$asn"| jq -C "$flags" 26 | fi 27 | else 28 | while read -r line ; do 29 | asn=$(echo $line | cut -d " " -f 2) 30 | flags="$1" 31 | 32 | if [[ "$asn" == "" ]] 33 | then 34 | echo_error "No ASN specified..." 35 | exit 36 | fi 37 | 38 | log "Queried for $asn" 39 | 40 | if [[ "$flags" != "" ]] 41 | then 42 | asn "$asn"| jq -r "$flags" 43 | else 44 | asn "$asn"| jq -C "$flags" 45 | fi 46 | done 47 | fi 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /bin/iptools-install: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DIR="$HOME/.ipi" 4 | CONFIG="$DIR/config.json" 5 | deps=(git jq curl) # TODO - write a checker to download deps if they dont exist 6 | 7 | if [[ "$1" != "" ]] 8 | then 9 | key="$1" 10 | if [[ -f "$DIR/.git/config" ]] 11 | then 12 | echo "Already installed, updating..." 13 | cd $DIR && git pull 14 | else 15 | git clone https://github.com/pry0cc/ipi $DIR 16 | fi 17 | 18 | echo "Writing config..." 19 | echo "{\"token\":\"$key\"}" > $CONFIG 20 | 21 | newpath="$PATH:$DIR/bin" 22 | export PATH="$newpath" 23 | 24 | echo -e "Please add the following to your .bashrc/.zshrc configuration:\nexport PATH=\"$newpath\"" 25 | else 26 | echo "Please supply a token, iptools-install " 27 | echo "You can obtain a token from https://ipinfo.io/account" 28 | echo "(You can login with google or github)" 29 | fi 30 | 31 | 32 | -------------------------------------------------------------------------------- /lib/colors.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | export NC='\033[0m' # Text Reset 4 | 5 | # Regular Colors 6 | export Black='\033[0;30m' # Black 7 | export Red='\033[0;31m' # Red 8 | export Green='\033[0;32m' # Green 9 | export Yellow='\033[0;33m' # Yellow 10 | export Blue='\033[0;34m' # Blue 11 | export Purple='\033[0;35m' # Purple 12 | export Cyan='\033[0;36m' # Cyan 13 | export White='\033[0;37m' # White 14 | 15 | # Bold 16 | export BBlack='\033[1;30m' # Black 17 | export BRed='\033[1;31m' # Red 18 | export BGreen='\033[1;32m' # Green 19 | export BYellow='\033[1;33m' # Yellow 20 | export BBlue='\033[1;34m' # Blue 21 | export BPurple='\033[1;35m' # Purple 22 | export BCyan='\033[1;36m' # Cyan 23 | export BWhite='\033[1;37m' # White 24 | -------------------------------------------------------------------------------- /lib/functions.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | log="$DIR/log.txt" 4 | token=$(cat $DIR/config.json | jq -r .token) 5 | url="https://ipinfo.io" 6 | 7 | echo_n() { 8 | echo -e "${White}$1${NC}" 9 | echo "NORMAL: $(date): $1" >> $log 10 | } 11 | 12 | echo_error() { 13 | echo -e "${Red}$1${NC}" 14 | echo "ERROR: $(date): $1" >> $log 15 | } 16 | 17 | log() { 18 | echo "LOG: $(date): $1" >> $log 19 | } 20 | 21 | info() { 22 | curl -s "$url/$1?token=$token" 23 | } 24 | 25 | domains() { 26 | curl -s "$url/domains/$1?token=$token" 27 | } 28 | 29 | hostinfo() { 30 | curl -s "https://host.io/api/web/$1?token=$token" 31 | } 32 | 33 | asn() { 34 | curl -s "$url/$1/json?token=$token" 35 | } 36 | --------------------------------------------------------------------------------