This works for the ASN API.
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, buts
is for silent mode andL
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 theprefixes
(IPv4) andprefixes6
(IPv6) arrays containing objects.