Saturday, October 24, 2020

IP and JQ to extract address

 So I wanted to try to extract just the IP address of a named network adapter using bash. There are lots of ways to do this, but it turns out that the linux ip command supports output to JSON. This gets me thinking jq. After testing on Manjaro and Amazon Linux 2, this is the most reliable command I found.

ip -4 -j a | jq -r '.[] | select(.ifname | contains("eth0")) | .addr_info[].local'

Obviously the interface name is going to be different on different systems

No comments:

Post a Comment

 RasPi Pico and an OLED Screen My project for this morning was to connect a small I2C OLED screen to Raspberry Pi Pico and make it do someth...