Skip to content

Instantly share code, notes, and snippets.

@hoangdh
Last active January 8, 2019 09:34
Show Gist options
  • Save hoangdh/cdb6a752c359f82f1e5b196111d39277 to your computer and use it in GitHub Desktop.
Save hoangdh/cdb6a752c359f82f1e5b196111d39277 to your computer and use it in GitHub Desktop.
Free IP address to ASN database - API iptoasn.com
#!/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