Getting all prefixes or parent ranges (IPv4 and IPv6) from the ASN API using JQ

This works for the ASN API.

:link: ASN API - Documentation

curl -sL ipinfo.io/AS62240?token=$token | jq -r '.prefixes[].netblock, .prefixes6[].netblock'
  • curl is used for making the get request.
  • -sL is not necessary here, but s is for silent mode and L is for redirect. I just use it out of force of habit.
  • ipinfo.io/AS62240?token=$token is the ASN API lookup endpoint. Please note that this API is not free.
  • jq is a JSON wrangling CLI app.
  • -r is for raw strings, removing the double quotes from the JSON values.
  • '.prefixes[].netblock, .prefixes6[].netblock' is a JSON query parameter that extracts the netblock value from the prefixes (IPv4) and prefixes6 (IPv6) arrays containing objects.