Closed n0n0x closed 6 years ago
Thanks for reporting this @n0n0x.
This API v3 based CLI is deprecated in favor of the Linode API v4 based CLI at https://www.github.com/linode/linode-cli (pip install linode-cli
).
Using the new CLI and jq
, you could split the public and private IPs as such:
$ linode-cli linodes view $LINODE_ID --json | jq '.[0].ipv4[] | select(test("192.168")|not)'
"23.239.29.162"
$ linode-cli linodes view $LINODE_ID --json | jq '.[0].ipv4[] | select(test("192.168"))'
"192.168.213.233"
You could also use the linode-cli networking ips-list
command with more advanced jq
selectors (this is the first time I am using jq
selectors, so this may not be the most efficient approach):
$ linode-cli networking ips-list --json | jq '.[] | select(.public and (.linode_id|contains($LINODE_ID)) and (.type|contains("ipv4"))) | .address'
"23.239.29.162"
You may find that you can reuse the jq
selector above to get the same behavior in the deprecated CLI.
Thanks again!
I can't easily do
linode -c linode -a list -j | jq '.[].ips[0]'
because theips
array is not ordered, [0] could be either an internal or external IP. It would be great if you can expand this IP list the following way:this way I can easily do
linode -c linode -a list -j | jq '.[].ips.external_ip'
to fetch only the external IP without hard-filtering out internal IPs