Last active
January 8, 2019 09:34
-
-
Save hoangdh/cdb6a752c359f82f1e5b196111d39277 to your computer and use it in GitHub Desktop.
Free IP address to ASN database - API iptoasn.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
IP2=$1 | |
IP=${IP2:-$(echo $(($RANDOM % 256)) $(($RANDOM % 256)) $(($RANDOM % 256)) $(($RANDOM % 256)) | sed 's/ /./g')} | |
if [[ "$IP" =~ ^(([1-9]?[0-9]|1[0-9][0-9]|2([0-4][0-9]|5[0-5]))\.){3}([1-9]?[0-9]|1[0-9][0-9]|2([0-4][0-9]|5[0-5]))$ ]]; then | |
echo -n "$IP: " | |
curl https://api.iptoasn.com/v1/as/ip/${IP} -s | grep -Eo '\"as_number\"(.+?)([0-9]),' | grep -Eo '[0-9]+' | |
# curl https://api.iptoasn.com/v1/as/ip/${IP} -s | sed 's/,/ /g;s/\"//g' | grep -Eo 'as_number.*' | awk {'print $1'} | cut -d':' -f2 | |
else | |
echo "$IP: Invaild." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment