# Add this to your ~/.bash_profile and make sure jq is installed and in your path. # Most of these rely on the BGPView API. # Dumps a list of IPv4 networks allocated to a specific BGP ASN function asn(){ curl -s https://api.bgpview.io/asn/$1/prefixes | jq '.data.ipv4_prefixes[].prefix' | tr -d \" } # Displays the ASN and brief description of the provider for a given IP Address function ipasn(){ curl -s https://api.bgpview.io/ip/$1 | jq '.data.prefixes[].asn' } # Shows the descriptions for a given ASN function asndesc(){ curl -s https://api.bgpview.io/asn/$1/prefixes | jq '.data.ipv4_prefixes[]| {name,description} | map(.) | @csv' | tr -d "\\\\\"" | sed s/","/" "/ | sort | uniq -c | sort -n } # Converts a dotted quad x.x.x.x IP to Long IP decimal format for database queries function ip2long() { if [ `echo $1 | tr '.' '\n' | wc -l` != "4" ]; then echo "No real ip given" else echo "$1" | awk -F\. '{print ($4)+($3*256)+($2*256*256)+($1*256*256*256)}' fi }